Search in sources :

Example 6 with FormItem

use of com.enonic.xp.form.FormItem 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)

Example 7 with FormItem

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

the class XmlContentTypeParserTest method assertResult.

private void assertResult() throws Exception {
    final ContentType result = this.builder.build();
    assertEquals("myapplication:mytype", result.getName().toString());
    assertEquals("All the Base Types", result.getDisplayName());
    assertEquals("description", result.getDescription());
    assertEquals("${firstName} ${lastName}", result.getDisplayNameExpression());
    assertEquals("Display Name Label", result.getDisplayNameLabel());
    assertEquals("myapplication:content", result.getSuperType().toString());
    assertEquals(false, result.isAbstract());
    assertEquals(true, result.isFinal());
    assertEquals(4, result.getForm().size());
    final FormItem item = result.getForm().getFormItem("myDate");
    assertNotNull(item);
    final Input input = (Input) item;
    assertEquals(InputTypeName.DATE.toString(), input.getInputType().toString());
    final FormItem contentSelectorItem = result.getForm().getFormItem("someonesParent");
    assertNotNull(contentSelectorItem);
    final Input contentSelectorInput = (Input) contentSelectorItem;
    assertEquals(InputTypeName.CONTENT_SELECTOR.toString(), contentSelectorInput.getInputType().toString());
    assertEquals("mytype", contentSelectorInput.getInputTypeConfig().getProperty("allowContentType").getValue());
    assertEquals(2, contentSelectorInput.getInputTypeConfig().getProperties("allowContentType").size());
    assertEquals("path1", contentSelectorInput.getInputTypeConfig().getProperty("allowPath").getValue());
    assertEquals(2, contentSelectorInput.getInputTypeConfig().getProperties("allowPath").size());
    assertEquals("system:reference", contentSelectorInput.getInputTypeConfig().getProperty("relationshipType").getValue());
    final InputTypeConfig config = input.getInputTypeConfig();
    assertNotNull(config);
    final Input defaultOccurrencesInput = result.getForm().getInput("defaultOccurrences");
    final Occurrences defaultOccurrences = defaultOccurrencesInput.getOccurrences();
    assertEquals(0, defaultOccurrences.getMinimum());
    assertEquals(1, defaultOccurrences.getMaximum());
}
Also used : Input(com.enonic.xp.form.Input) ContentType(com.enonic.xp.schema.content.ContentType) FormItem(com.enonic.xp.form.FormItem) InputTypeConfig(com.enonic.xp.inputtype.InputTypeConfig) Occurrences(com.enonic.xp.form.Occurrences)

Example 8 with FormItem

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

the class XmlContentTypeParserTest method testI18n_optionSet.

@Test
public void testI18n_optionSet() throws Exception {
    parse(this.parser, "-i18n.xml");
    final ContentType result = this.builder.build();
    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.label", radioOptionSet.getLabelI18nKey());
    final Input inputInsideOption = radioOptionSet.getFormItems().getInput(FormItemPath.from("option_1.text-input"));
    assertEquals("translated.help-text", inputInsideOption.getHelpTextI18nKey());
    assertEquals("translated.label", inputInsideOption.getLabelI18nKey());
    final FormOptionSetOption radioOption = radioOptionSet.getFormItems().getItemByName("option_1").toFormOptionSetOption();
    assertEquals("translated.help-text", radioOption.getHelpTextI18nKey());
    assertEquals("translated.label", radioOption.getLabelI18nKey());
}
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) FormOptionSetOption(com.enonic.xp.form.FormOptionSetOption) Test(org.junit.jupiter.api.Test)

Example 9 with FormItem

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

the class XmlContentTypeParserTest method testI18n_fieldSet.

@Test
public void testI18n_fieldSet() throws Exception {
    parse(this.parser, "-i18n.xml");
    final ContentType result = this.builder.build();
    FormItem item = null;
    for (final FormItem next : result.getForm().getFormItems()) {
        if (next.getName().startsWith("fieldSet")) {
            item = next;
        }
    }
    assertNotNull(item);
    final FieldSet fieldSet = (FieldSet) item;
    assertEquals("translated.label", fieldSet.getLabelI18nKey());
    final Input inputInsideFieldSet = fieldSet.getFormItems().getInput(FormItemPath.from("textLine2"));
    assertEquals("translated.help-text", inputInsideFieldSet.getHelpTextI18nKey());
    assertEquals("translated.label", inputInsideFieldSet.getLabelI18nKey());
}
Also used : FieldSet(com.enonic.xp.form.FieldSet) Input(com.enonic.xp.form.Input) ContentType(com.enonic.xp.schema.content.ContentType) FormItem(com.enonic.xp.form.FormItem) Test(org.junit.jupiter.api.Test)

Example 10 with FormItem

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

the class OccurrenceValidator method validate.

private static void validate(final Iterable<FormItem> formItems, final List<PropertySet> parentDataSets, final ValidationErrors.Builder validationErrorsBuilder) {
    for (FormItem formItem : formItems) {
        validateOccurrences(formItem, parentDataSets, validationErrorsBuilder);
        if (formItem instanceof FormItemSet) {
            final List<PropertySet> dataSets = getDataSets(formItem.getName(), parentDataSets);
            validate(((FormItemSet) formItem).getFormItems(), dataSets, validationErrorsBuilder);
        } else if (formItem instanceof FieldSet) {
            validate(((FieldSet) formItem).formItemIterable(), parentDataSets, validationErrorsBuilder);
        } else if (formItem instanceof FormOptionSet) {
            validateFormOptionSetSelection((FormOptionSet) formItem, parentDataSets, validationErrorsBuilder);
        }
    }
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) FieldSet(com.enonic.xp.form.FieldSet) FormItem(com.enonic.xp.form.FormItem) PropertySet(com.enonic.xp.data.PropertySet) FormItemSet(com.enonic.xp.form.FormItemSet)

Aggregations

FormItem (com.enonic.xp.form.FormItem)18 Input (com.enonic.xp.form.Input)9 ContentType (com.enonic.xp.schema.content.ContentType)6 Test (org.junit.jupiter.api.Test)6 FormItemSet (com.enonic.xp.form.FormItemSet)5 FormOptionSet (com.enonic.xp.form.FormOptionSet)5 FieldSet (com.enonic.xp.form.FieldSet)4 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)4 Form (com.enonic.xp.form.Form)3 ExtraData (com.enonic.xp.content.ExtraData)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 Occurrences (com.enonic.xp.form.Occurrences)2 InputTypeConfig (com.enonic.xp.inputtype.InputTypeConfig)2 XData (com.enonic.xp.schema.xdata.XData)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ExtraDatas (com.enonic.xp.content.ExtraDatas)1 PropertySet (com.enonic.xp.data.PropertySet)1 FormItems (com.enonic.xp.form.FormItems)1 InlineMixin (com.enonic.xp.form.InlineMixin)1