Search in sources :

Example 26 with FormItemSet

use of com.enonic.xp.form.FormItemSet in project xp by enonic.

the class ContentTypeHandlerTest method getForm.

private Form getForm() {
    Input myTextLine = Input.create().name("myTextLine").inputType(InputTypeName.TEXT_LINE).label("My text line").customText("Some custom text").helpText("Some help text").required(true).inputTypeConfig(InputTypeConfig.create().property(InputTypeProperty.create("regexp", "\\b\\d{3}-\\d{2}-\\d{4}\\b").build()).build()).build();
    Input myCustomInput = Input.create().name("myCheckbox").inputType(InputTypeName.CHECK_BOX).label("My checkbox input").required(false).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "checked").build()).build()).build();
    final InputTypeProperty option1 = InputTypeProperty.create("option", "Option One").attribute("value", "one").build();
    final InputTypeProperty option2 = InputTypeProperty.create("option", "Option Two").attribute("value", "two").build();
    Input radioButtonInput = Input.create().name("myRadioButton").inputType(InputTypeName.RADIO_BUTTON).label("Radio button").inputTypeConfig(InputTypeConfig.create().property(option1).property(option2).build()).build();
    FieldSet myFieldSet = FieldSet.create().name("myFieldSet").label("My field set").addFormItem(Input.create().name("myTextLineInFieldSet").inputType(InputTypeName.TEXT_LINE).label("My text line").required(false).build()).build();
    FormItemSet myFormItemSet = FormItemSet.create().name("myFormItemSet").label("My form item set").addFormItem(Input.create().name("myTextLine").inputType(InputTypeName.TEXT_LINE).label("My text line").required(false).build()).build();
    final FormOptionSet formOptionSet = FormOptionSet.create().name("myOptionSet").label("My option set").helpText("Option set help text").addOptionSetOption(FormOptionSetOption.create().name("myOptionSetOption1").label("option label1").helpText("Option help text").addFormItem(Input.create().name("myTextLine1").label("myTextLine1").inputType(InputTypeName.TEXT_LINE).build()).build()).addOptionSetOption(FormOptionSetOption.create().name("myOptionSetOption2").label("option label2").helpText("Option help text").addFormItem(Input.create().name("myTextLine2").label("myTextLine2").inputType(InputTypeName.TEXT_LINE).build()).build()).build();
    return Form.create().addFormItem(myTextLine).addFormItem(myCustomInput).addFormItem(radioButtonInput).addFormItem(myFieldSet).addFormItem(myFormItemSet).addFormItem(formOptionSet).build();
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) Input(com.enonic.xp.form.Input) FieldSet(com.enonic.xp.form.FieldSet) InputTypeProperty(com.enonic.xp.inputtype.InputTypeProperty) FormItemSet(com.enonic.xp.form.FormItemSet)

Example 27 with FormItemSet

use of com.enonic.xp.form.FormItemSet in project xp by enonic.

the class CreateContentHandlerTest method mockCreateContent.

private void mockCreateContent() {
    when(this.contentService.create(any(CreateContentParams.class))).thenAnswer(mock -> createContent((CreateContentParams) mock.getArguments()[0]));
    final FormItemSet eSet = FormItemSet.create().name("e").addFormItem(Input.create().label("f").name("f").inputType(InputTypeName.DOUBLE).build()).addFormItem(Input.create().label("g").name("g").inputType(InputTypeName.CHECK_BOX).build()).build();
    final FormItemSet dSet = FormItemSet.create().name("d").addFormItem(eSet).build();
    final ContentType contentType = ContentType.create().name("test:myContentType").superType(ContentTypeName.structured()).addFormItem(Input.create().label("a").name("a").inputType(InputTypeName.LONG).build()).addFormItem(Input.create().label("b").name("b").inputType(InputTypeName.LONG).build()).addFormItem(Input.create().label("c").name("c").occurrences(0, 10).inputType(InputTypeName.TEXT_LINE).build()).addFormItem(dSet).build();
    GetContentTypeParams getContentType = GetContentTypeParams.from(ContentTypeName.from("test:myContentType"));
    when(this.contentTypeService.getByName(Mockito.eq(getContentType))).thenReturn(contentType);
    final PropertyTree extraData = new PropertyTree();
    extraData.addDouble("a", 1.0);
    extraData.addBoolean("b", true);
    final XData xData = XData.create().name(XDataName.from("com.enonic.myapplication:myschema")).addFormItem(Input.create().label("a").name("a").inputType(InputTypeName.DOUBLE).build()).addFormItem(Input.create().label("b").name("b").inputType(InputTypeName.CHECK_BOX).build()).build();
    final SiteDescriptor siteDescriptor1 = SiteDescriptor.create().form(Form.create().addFormItem(Input.create().label("a").name("a").inputType(InputTypeName.TEXT_LINE).build()).addFormItem(Input.create().label("b").name("b").inputType(InputTypeName.CHECK_BOX).build()).build()).build();
    final SiteDescriptor siteDescriptor2 = SiteDescriptor.create().form(Form.create().addFormItem(Input.create().label("c").name("c").inputType(InputTypeName.LONG).build()).build()).build();
    when(this.siteService.getDescriptor(ApplicationKey.from("appKey1"))).thenReturn(siteDescriptor1);
    when(this.siteService.getDescriptor(ApplicationKey.from("appKey2"))).thenReturn(siteDescriptor2);
    when(this.xDataService.getByName(Mockito.eq(XDataName.from("com.enonic.myapplication:myschema")))).thenReturn(xData);
    when(this.mixinService.inlineFormItems(any(Form.class))).then(returnsFirstArg());
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) Form(com.enonic.xp.form.Form) CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) XData(com.enonic.xp.schema.xdata.XData) FormItemSet(com.enonic.xp.form.FormItemSet)

Aggregations

FormItemSet (com.enonic.xp.form.FormItemSet)27 Test (org.junit.jupiter.api.Test)17 FormOptionSet (com.enonic.xp.form.FormOptionSet)10 Form (com.enonic.xp.form.Form)9 Input (com.enonic.xp.form.Input)8 PropertyTree (com.enonic.xp.data.PropertyTree)6 FieldSet (com.enonic.xp.form.FieldSet)6 Content (com.enonic.xp.content.Content)5 ValidationErrors (com.enonic.xp.content.ValidationErrors)5 FormItem (com.enonic.xp.form.FormItem)5 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)5 ContentType (com.enonic.xp.schema.content.ContentType)5 DataValidationError (com.enonic.xp.content.DataValidationError)3 FormDefaultValuesProcessor (com.enonic.xp.form.FormDefaultValuesProcessor)3 PropertySet (com.enonic.xp.data.PropertySet)2 InlineMixin (com.enonic.xp.form.InlineMixin)2 Occurrences (com.enonic.xp.form.Occurrences)2 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)2 XData (com.enonic.xp.schema.xdata.XData)2 CreateContentParams (com.enonic.xp.content.CreateContentParams)1