Search in sources :

Example 1 with FormItemSet

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

the class JsonToPropertyTreeTranslatorTest method createFormForAllInputTypes.

private Form createFormForAllInputTypes() {
    final FormItemSet set = FormItemSet.create().name("set").addFormItem(Input.create().name("setString").label("String").inputType(InputTypeName.TEXT_LINE).build()).addFormItem(Input.create().name("setDouble").label("Double").inputType(InputTypeName.DOUBLE).build()).build();
    final FormOptionSet formOptionSet = FormOptionSet.create().name("myOptionSet").label("My option set").addOptionSetOption(FormOptionSetOption.create().name("myOptionSetOption1").label("option label1").addFormItem(Input.create().name("myTextLine1").label("myTextLine1").inputType(InputTypeName.TEXT_LINE).build()).build()).addOptionSetOption(FormOptionSetOption.create().name("myOptionSetOption2").label("option label2").addFormItem(Input.create().name("myTextLine2").label("myTextLine2").inputType(InputTypeName.TEXT_LINE).build()).build()).build();
    return Form.create().addFormItem(Input.create().name("textLine").label("Textline").inputType(InputTypeName.TEXT_LINE).build()).addFormItem(Input.create().name("stringArray").label("String array").inputType(InputTypeName.TEXT_LINE).build()).addFormItem(Input.create().name("double").label("Double").inputType(InputTypeName.DOUBLE).build()).addFormItem(Input.create().name("long").label("Long").inputType(InputTypeName.LONG).build()).addFormItem(Input.create().name("comboBox").label("Combobox").inputType(InputTypeName.COMBO_BOX).inputTypeProperty(InputTypeProperty.create("option", "label1").attribute("value", "value1").build()).inputTypeProperty(InputTypeProperty.create("option", "label2").attribute("value", "value2").build()).build()).addFormItem(Input.create().name("checkbox").label("Checkbox").inputType(InputTypeName.CHECK_BOX).build()).addFormItem(Input.create().name("tag").label("Tag").inputType(InputTypeName.TAG).build()).addFormItem(Input.create().name("contentSelector").label("Content selector").inputType(InputTypeName.CONTENT_SELECTOR).inputTypeProperty(InputTypeProperty.create("allowContentType", ContentTypeName.folder().toString()).build()).inputTypeProperty(InputTypeProperty.create("relationshipType", RelationshipTypeName.REFERENCE.toString()).build()).build()).addFormItem(Input.create().name("contentTypeFilter").label("Content type filter").inputType(InputTypeName.CONTENT_TYPE_FILTER).build()).addFormItem(Input.create().name("siteConfigurator").inputType(InputTypeName.SITE_CONFIGURATOR).label("Site configurator").build()).addFormItem(Input.create().name("date").label("Date").inputType(InputTypeName.DATE).build()).addFormItem(Input.create().name("time").label("Time").inputType(InputTypeName.TIME).build()).addFormItem(Input.create().name("geoPoint").label("Geo point").inputType(InputTypeName.GEO_POINT).build()).addFormItem(Input.create().name("htmlArea").label("Html area").inputType(InputTypeName.HTML_AREA).build()).addFormItem(Input.create().name("localDateTime").label("Local datetime").inputType(InputTypeName.DATE_TIME).inputTypeProperty(InputTypeProperty.create("timezone", "false").build()).build()).addFormItem(Input.create().name("dateTime").label("Datetime").inputType(InputTypeName.DATE_TIME).inputTypeProperty(InputTypeProperty.create("timezone", "true").build()).build()).addFormItem(Input.create().name("media").label("Image Uploader").inputType(InputTypeName.IMAGE_UPLOADER).build()).addFormItem(set).addFormItem(formOptionSet).build();
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) FormItemSet(com.enonic.xp.form.FormItemSet)

Example 2 with FormItemSet

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

the class ContentTypeTest method address.

@Test
public void address() {
    FormItemSet formItemSet = FormItemSet.create().name("address").build();
    formItemSet.add(Input.create().name("label").label("Label").inputType(InputTypeName.TEXT_LINE).build());
    formItemSet.add(Input.create().name("street").label("Street").inputType(InputTypeName.TEXT_LINE).build());
    formItemSet.add(Input.create().name("postalNo").label("Postal No").inputType(InputTypeName.TEXT_LINE).build());
    formItemSet.add(Input.create().name("country").label("Country").inputType(InputTypeName.TEXT_LINE).build());
    ContentType contentType = ContentType.create().superType(ContentTypeName.structured()).name("myapplication:test").addFormItem(Input.create().name("title").label("Title").inputType(InputTypeName.TEXT_LINE).build()).addFormItem(formItemSet).build();
    assertEquals("title", contentType.getForm().getInput("title").getPath().toString());
    assertEquals("address.label", contentType.getForm().getInput("address.label").getPath().toString());
    assertEquals("address.street", contentType.getForm().getInput("address.street").getPath().toString());
    assertEquals("address.postalNo", contentType.getForm().getInput("address.postalNo").getPath().toString());
    assertEquals("address.country", contentType.getForm().getInput("address.country").getPath().toString());
}
Also used : FormItemSet(com.enonic.xp.form.FormItemSet) Test(org.junit.jupiter.api.Test)

Example 3 with FormItemSet

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

the class XmlContentTypeParserTest method testI18n_itemSet.

@Test
public void testI18n_itemSet() throws Exception {
    parse(this.parser, "-i18n.xml");
    final ContentType result = this.builder.build();
    final FormItem item = result.getForm().getFormItem("item-set");
    assertNotNull(item);
    final FormItemSet formItemSet = (FormItemSet) item;
    assertEquals("translated.label", formItemSet.getLabelI18nKey());
    assertEquals("translated.help-text", formItemSet.getHelpTextI18nKey());
    final Input inputInsideFormItemSet = formItemSet.getFormItems().getInput(FormItemPath.from("textLine1"));
    assertEquals("translated.help-text", inputInsideFormItemSet.getHelpTextI18nKey());
    assertEquals("translated.label", inputInsideFormItemSet.getLabelI18nKey());
}
Also used : Input(com.enonic.xp.form.Input) ContentType(com.enonic.xp.schema.content.ContentType) FormItem(com.enonic.xp.form.FormItem) FormItemSet(com.enonic.xp.form.FormItemSet) Test(org.junit.jupiter.api.Test)

Example 4 with FormItemSet

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

the class XmlContentTypeParserTest method assertOptionSetResult.

private void assertOptionSetResult() throws Exception {
    final ContentType result = this.builder.build();
    assertEquals("myapplication:mytype", result.getName().toString());
    assertEquals("OptionSet", result.getDisplayName());
    assertEquals("OptionSet for testing", result.getDescription());
    assertEquals("base:structured", result.getSuperType().toString());
    assertFalse(result.isAbstract());
    assertFalse(result.isFinal());
    assertEquals(2, result.getForm().size());
    final FormItem item = result.getForm().getFormItem("radioOptionSet");
    assertNotNull(item);
    final FormOptionSet radioOptionSet = (FormOptionSet) item;
    assertEquals(FormItemType.FORM_OPTION_SET, radioOptionSet.getType());
    final FormItems radioOptions = radioOptionSet.getFormItems();
    assertEquals(2, radioOptions.size());
    FormOptionSetOption radioOption1 = radioOptions.getItemByName("option_1").toFormOptionSetOption();
    FormOptionSetOption radioOption2 = radioOptions.getItemByName("option_2").toFormOptionSetOption();
    assertEquals(FormItemType.FORM_OPTION_SET_OPTION, radioOption1.getType());
    assertEquals(FormItemType.FORM_OPTION_SET_OPTION, radioOption2.getType());
    assertFalse(radioOption1.isDefaultOption());
    assertFalse(radioOption2.isDefaultOption());
    assertEquals(0, radioOption2.getFormItems().size());
    assertEquals(2, radioOption1.getFormItems().size());
    final Input textInput = radioOption1.getFormItems().getItemByName("text-input").toInput();
    assertEquals(InputTypeName.TEXT_LINE.toString(), textInput.getInputType().toString());
    assertEquals("Text input", textInput.getHelpText());
    final FormItemSet formItemSet = radioOption1.getFormItems().getItemByName("minimum3").toFormItemSet();
    assertEquals(2, formItemSet.getFormItems().size());
    final FormOptionSet checkOptionSet = result.getForm().getFormItem("checkOptionSet").toFormOptionSet();
    assertEquals(FormItemType.FORM_OPTION_SET, checkOptionSet.getType());
    assertEquals("Multi selection", checkOptionSet.getLabel());
    assertTrue(checkOptionSet.isExpanded());
    final Occurrences checkOptionSetOccurrences = checkOptionSet.getOccurrences();
    assertEquals(0, checkOptionSetOccurrences.getMinimum());
    assertEquals(1, checkOptionSetOccurrences.getMaximum());
    final FormItems checkOptions = checkOptionSet.getFormItems();
    assertEquals(4, checkOptions.size());
    // check option set 1st option
    final FormOptionSetOption checkOption1 = checkOptions.getItemByName("option_1").toFormOptionSetOption();
    assertTrue(checkOption1.isDefaultOption());
    assertEquals(0, checkOption1.getFormItems().size());
    // check option set 2nd option
    final FormOptionSetOption checkOption2 = checkOptions.getItemByName("option_2").toFormOptionSetOption();
    assertTrue(checkOption2.isDefaultOption());
    assertEquals(1, checkOption2.getFormItems().size());
    // nested option set
    final FormOptionSet nestedOptionSet = checkOption2.getFormItems().getItemByName("nestedOptionSet").toFormOptionSet();
    final FormItems nestedSetOptions = nestedOptionSet.getFormItems();
    assertEquals(2, nestedSetOptions.size());
    assertFalse(nestedOptionSet.isExpanded());
    final FormOptionSetOption nestedSetOption1 = nestedSetOptions.getItemByName("option2_1").toFormOptionSetOption();
    assertFalse(nestedSetOption1.isDefaultOption());
    assertEquals(1, nestedSetOption1.getFormItems().size());
    final FormOptionSetOption nestedSetOption2 = nestedSetOptions.getItemByName("option2_2").toFormOptionSetOption();
    assertTrue(nestedSetOption2.isDefaultOption());
    assertEquals(1, nestedSetOption2.getFormItems().size());
    // check option set 3rd option
    final FormOptionSetOption checkOption3 = checkOptions.getItemByName("option_3").toFormOptionSetOption();
    assertFalse(checkOption3.isDefaultOption());
    assertEquals(1, checkOption3.getFormItems().size());
    final Input imageSelectorInput = checkOption3.getFormItems().getItemByName("imageselector").toInput();
    assertEquals("mytype", imageSelectorInput.getInputTypeConfig().getProperty("allowContentType").getValue());
    assertEquals(2, imageSelectorInput.getInputTypeConfig().getProperties("allowContentType").size());
    assertEquals("path1", imageSelectorInput.getInputTypeConfig().getProperty("allowPath").getValue());
    assertEquals(2, imageSelectorInput.getInputTypeConfig().getProperties("allowPath").size());
    assertEquals("system:reference", imageSelectorInput.getInputTypeConfig().getProperty("relationshipType").getValue());
    final Occurrences imageSelectorOccurrences = imageSelectorInput.getOccurrences();
    assertEquals(1, imageSelectorOccurrences.getMinimum());
    assertEquals(1, imageSelectorOccurrences.getMaximum());
    // check option set 4th option
    final FormOptionSetOption checkOption4 = checkOptions.getItemByName("option_4").toFormOptionSetOption();
    assertFalse(checkOption4.isDefaultOption());
    assertEquals(2, checkOption4.getFormItems().size());
    final Input doubleInput = checkOption4.getFormItems().getItemByName("double").toInput();
    final Input longInput = checkOption4.getFormItems().getItemByName("long").toInput();
    assertEquals(InputTypeName.DOUBLE.toString(), doubleInput.getInputType().toString());
    assertEquals(InputTypeName.LONG.toString(), longInput.getInputType().toString());
    final Occurrences longInputOccurrences = longInput.getOccurrences();
    assertEquals(0, longInputOccurrences.getMinimum());
    assertEquals(1, longInputOccurrences.getMaximum());
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) Input(com.enonic.xp.form.Input) ContentType(com.enonic.xp.schema.content.ContentType) FormItem(com.enonic.xp.form.FormItem) FormItems(com.enonic.xp.form.FormItems) Occurrences(com.enonic.xp.form.Occurrences) FormOptionSetOption(com.enonic.xp.form.FormOptionSetOption) FormItemSet(com.enonic.xp.form.FormItemSet)

Example 5 with FormItemSet

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

the class XmlContentTypeParserTest method testI18nParseOmittingElementValue.

@Test
public void testI18nParseOmittingElementValue() throws Exception {
    parse(this.parser, "-i18n-only-attribute.xml");
    final ContentType result = this.builder.build();
    assertEquals("translated.display-name", result.getDisplayNameI18nKey());
    assertEquals("translated.description", result.getDescriptionI18nKey());
    // input type
    final Input input = (Input) result.getForm().getFormItem("textLine");
    assertEquals("translated.label", input.getLabelI18nKey());
    assertEquals("translated.label", input.getLabel());
    assertEquals("translated.help-text", input.getHelpTextI18nKey());
    assertEquals("translated.help-text", input.getHelpText());
    // option set
    final FormItem item = result.getForm().getFormItem("radioOptionSet");
    assertNotNull(item);
    final FormOptionSet radioOptionSet = (FormOptionSet) item;
    assertEquals(FormItemType.FORM_OPTION_SET, radioOptionSet.getType());
    assertEquals("translated.help-text", radioOptionSet.getHelpTextI18nKey());
    assertEquals("translated.help-text", radioOptionSet.getHelpText());
    assertEquals("translated.label", radioOptionSet.getLabelI18nKey());
    assertEquals("translated.label", radioOptionSet.getLabel());
    final Input inputInsideOption = radioOptionSet.getFormItems().getInput(FormItemPath.from("option_1.text-input"));
    assertEquals("translated.help-text", inputInsideOption.getHelpTextI18nKey());
    assertEquals("translated.help-text", inputInsideOption.getHelpText());
    assertEquals("translated.label", inputInsideOption.getLabelI18nKey());
    assertEquals("translated.label", inputInsideOption.getLabel());
    final FormOptionSetOption radioOption = radioOptionSet.getFormItems().getItemByName("option_1").toFormOptionSetOption();
    assertEquals("translated.help-text", radioOption.getHelpTextI18nKey());
    assertEquals("translated.help-text", radioOption.getHelpText());
    assertEquals("translated.label", radioOption.getLabelI18nKey());
    assertEquals("translated.label", radioOption.getLabel());
    // field set
    FormItem fieldSetItem = null;
    for (final FormItem next : result.getForm().getFormItems()) {
        if (next.getName().startsWith("fieldSet")) {
            fieldSetItem = next;
        }
    }
    assertNotNull(fieldSetItem);
    final FieldSet fieldSet = (FieldSet) fieldSetItem;
    assertEquals("translated.label", fieldSet.getLabelI18nKey());
    assertEquals("translated.label", fieldSet.getLabel());
    final Input inputInsideFieldSet = fieldSet.getFormItems().getInput(FormItemPath.from("textLine2"));
    assertEquals("translated.help-text", inputInsideFieldSet.getHelpTextI18nKey());
    assertEquals("translated.help-text", inputInsideFieldSet.getHelpText());
    assertEquals("translated.label", inputInsideFieldSet.getLabelI18nKey());
    assertEquals("translated.label", inputInsideFieldSet.getLabel());
    // item set
    final FormItem itemSet = result.getForm().getFormItem("item-set");
    assertNotNull(item);
    final FormItemSet formItemSet = (FormItemSet) itemSet;
    assertEquals("translated.label", formItemSet.getLabelI18nKey());
    assertEquals("translated.label", formItemSet.getLabel());
    assertEquals("translated.help-text", formItemSet.getHelpTextI18nKey());
    assertEquals("translated.help-text", formItemSet.getHelpText());
    final Input inputInsideFormItemSet = formItemSet.getFormItems().getInput(FormItemPath.from("textLine1"));
    assertEquals("translated.help-text", inputInsideFormItemSet.getHelpTextI18nKey());
    assertEquals("translated.help-text", inputInsideFormItemSet.getHelpText());
    assertEquals("translated.label", inputInsideFormItemSet.getLabelI18nKey());
    assertEquals("translated.label", inputInsideFormItemSet.getLabel());
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) Input(com.enonic.xp.form.Input) FieldSet(com.enonic.xp.form.FieldSet) ContentType(com.enonic.xp.schema.content.ContentType) FormItem(com.enonic.xp.form.FormItem) FormOptionSetOption(com.enonic.xp.form.FormOptionSetOption) FormItemSet(com.enonic.xp.form.FormItemSet) Test(org.junit.jupiter.api.Test)

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