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());
}
use of com.enonic.xp.form.FormItemSet in project xp by enonic.
the class ContentTypeTest method layout_inside_formItemSet.
@Test
public void layout_inside_formItemSet() {
ContentType contentType = ContentType.create().name("myapplication:test").superType(ContentTypeName.structured()).build();
FieldSet layout = FieldSet.create().label("Personalia").name("personalia").addFormItem(Input.create().name("eyeColour").label("Eye color").inputType(InputTypeName.TEXT_LINE).build()).build();
FormItemSet myFormItemSet = FormItemSet.create().name("mySet").addFormItem(layout).build();
contentType.getForm().getFormItems().add(myFormItemSet);
assertEquals("mySet.eyeColour", contentType.getForm().getInput("mySet.eyeColour").getPath().toString());
}
use of com.enonic.xp.form.FormItemSet in project xp by enonic.
the class ContentTypeTest method formItemSet_in_formItemSet.
@Test
public void formItemSet_in_formItemSet() {
FormItemSet formItemSet = FormItemSet.create().name("top-set").addFormItem(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).build()).addFormItem(FormItemSet.create().name("inner-set").addFormItem(Input.create().name("myInnerInput").label("Inner input").inputType(InputTypeName.TEXT_LINE).build()).build()).build();
ContentType contentType = ContentType.create().superType(ContentTypeName.structured()).name("myapplication:test").addFormItem(formItemSet).build();
assertEquals("top-set", contentType.getForm().getFormItemSet("top-set").getPath().toString());
assertEquals("top-set.myInput", contentType.getForm().getInput("top-set.myInput").getPath().toString());
assertEquals("top-set.inner-set", contentType.getForm().getFormItemSet("top-set.inner-set").getPath().toString());
assertEquals("top-set.inner-set.myInnerInput", contentType.getForm().getInput("top-set.inner-set.myInnerInput").getPath().toString());
}
use of com.enonic.xp.form.FormItemSet in project xp by enonic.
the class MixinTest method adding_a_formItemSetMixin_to_another_formItemSetMixin_throws_exception.
@Test
public void adding_a_formItemSetMixin_to_another_formItemSetMixin_throws_exception() {
Mixin ageMixin = Mixin.create().name("myapplication:age").addFormItem(Input.create().name("age").label("Age").inputType(InputTypeName.TEXT_LINE).build()).build();
final FormItemSet personFormItemSet = FormItemSet.create().name("person").addFormItem(Input.create().name("name").label("Name").inputType(InputTypeName.TEXT_LINE).build()).addFormItem(InlineMixin.create(ageMixin).build()).build();
Mixin addressMixin = Mixin.create().name(MixinName.from(ApplicationKey.from("myapplication"), "address")).addFormItem(FormItemSet.create().name("address").addFormItem(Input.create().inputType(InputTypeName.TEXT_LINE).name("street").label("Street").build()).addFormItem(Input.create().inputType(InputTypeName.TEXT_LINE).name("postalCode").label("Postal code").build()).addFormItem(Input.create().inputType(InputTypeName.TEXT_LINE).name("postalPlace").label("Postal place").build()).build()).build();
try {
personFormItemSet.add(InlineMixin.create(addressMixin).build());
} catch (Exception e) {
assertTrue(e instanceof IllegalArgumentException);
assertEquals("A Mixin cannot reference other Mixins unless it is of type InputMixin: FormItemSetMixin", e.getMessage());
}
}
use of com.enonic.xp.form.FormItemSet in project xp by enonic.
the class FormJsonToPropertyTreeTranslatorTest 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();
}
Aggregations