use of com.enonic.xp.form.FormItem in project xp by enonic.
the class ContentTypeMapper method serializeOption.
private void serializeOption(final MapGenerator gen, final FormOptionSetOption option) {
gen.map();
gen.value("name", option.getName());
gen.value("label", option.getLabel());
gen.value("helpText", option.getHelpText());
gen.value("default", option.isDefaultOption());
gen.array("items");
for (FormItem formItem : option.getFormItems()) {
serializeItem(gen, formItem);
}
gen.end();
gen.end();
}
use of com.enonic.xp.form.FormItem in project xp by enonic.
the class ContentTypeMapper method serializeForm.
private void serializeForm(final MapGenerator gen, final Form form) {
gen.array("form");
for (FormItem item : form) {
serializeItem(gen, item);
}
gen.end();
}
use of com.enonic.xp.form.FormItem in project xp by enonic.
the class SiteDescriptorTest method create_site_descriptor.
@Test
public void create_site_descriptor() {
// Builds a Form
final FormItem formItem = Input.create().name("input").label("Input").inputType(InputTypeName.DOUBLE).build();
final Form form = Form.create().addFormItem(formItem).build();
// Builds MixinNames
List<XDataMapping> xDataMappingList = new ArrayList<>();
xDataMappingList.add(XDataMapping.create().xDataName(XDataName.from("myapplication:my")).build());
XDataMappings xDataMappings = XDataMappings.from(xDataMappingList);
// Builds a SiteDescriptor
SiteDescriptor siteDescriptor = SiteDescriptor.create().form(form).xDataMappings(xDataMappings).build();
assertEquals(form, siteDescriptor.getForm());
assertEquals(xDataMappings, siteDescriptor.getXDataMappings());
}
use of com.enonic.xp.form.FormItem 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());
}
use of com.enonic.xp.form.FormItem 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());
}
Aggregations