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 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 OccurrenceValidatorTest method given_required_set_with_no_data_and_other_set_with_data_when_validate_then_MinimumOccurrencesValidationError.
@Test
public void given_required_set_with_no_data_and_other_set_with_data_when_validate_then_MinimumOccurrencesValidationError() {
// setup
contentType.getForm().getFormItems().add(Input.create().name("name").label("Input").inputType(InputTypeName.TEXT_LINE).build());
FormItemSet personalia = FormItemSet.create().name("personalia").multiple(false).required(true).build();
personalia.add(Input.create().name("eyeColour").label("Eye color").inputType(InputTypeName.TEXT_LINE).build());
personalia.add(Input.create().name("hairColour").label("Hair color").inputType(InputTypeName.TEXT_LINE).build());
contentType.getForm().getFormItems().add(personalia);
FormItemSet crimes = FormItemSet.create().name("crimes").multiple(true).build();
contentType.getForm().getFormItems().add(crimes);
crimes.add(Input.create().name("description").label("Description").inputType(InputTypeName.TEXT_LINE).build());
crimes.add(Input.create().name("year").label("Year").inputType(InputTypeName.TEXT_LINE).build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("name", "Thomas");
content.getData().setString("crimes[0].description", "Stole tomatoes from neighbour");
content.getData().setString("crimes[0].year", "1989");
content.getData().setString("crimes[1].description", "Stole a chocolate from the Matbua shop");
content.getData().setString("crimes[1].year", "1990");
// exercise
final ValidationErrors validationResults = validate(content);
assertThat(validationResults.stream().findFirst()).containsInstanceOf(DataValidationError.class).get().extracting(ValidationError::getArgs, LIST).containsExactly("personalia", 1, 0);
}
use of com.enonic.xp.form.FormItemSet in project xp by enonic.
the class InputValidationVisitorTest method validateItemSetInvalid.
@Test
public void validateItemSetInvalid() throws Exception {
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();
Form form = Form.create().addFormItem(myFormItemSet).build();
PropertyTree propertyTree = new PropertyTree();
propertyTree.setLong("myFormItemSet.myTextLine", 33L);
final InputValidationVisitor validationVisitor = new InputValidationVisitor(propertyTree, InputTypes.BUILTIN);
assertThrows(InputTypeValidationException.class, () -> validationVisitor.traverse(form));
}
use of com.enonic.xp.form.FormItemSet in project xp by enonic.
the class InputValidationVisitorTest method validateItemSetValid.
@Test
public void validateItemSetValid() throws Exception {
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();
Form form = Form.create().addFormItem(myFormItemSet).build();
PropertyTree propertyTree = new PropertyTree();
propertyTree.setString("myFormItemSet.myTextLine", "33");
final InputValidationVisitor validationVisitor = new InputValidationVisitor(propertyTree, InputTypes.BUILTIN);
validationVisitor.traverse(form);
}
Aggregations