Search in sources :

Example 16 with FormItemSet

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());
}
Also used : FormItemSet(com.enonic.xp.form.FormItemSet) Test(org.junit.jupiter.api.Test)

Example 17 with FormItemSet

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());
}
Also used : FieldSet(com.enonic.xp.form.FieldSet) FormItemSet(com.enonic.xp.form.FormItemSet) Test(org.junit.jupiter.api.Test)

Example 18 with FormItemSet

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);
}
Also used : ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) FormItemSet(com.enonic.xp.form.FormItemSet) DataValidationError(com.enonic.xp.content.DataValidationError) Test(org.junit.jupiter.api.Test)

Example 19 with FormItemSet

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));
}
Also used : Form(com.enonic.xp.form.Form) PropertyTree(com.enonic.xp.data.PropertyTree) FormItemSet(com.enonic.xp.form.FormItemSet) Test(org.junit.jupiter.api.Test)

Example 20 with FormItemSet

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);
}
Also used : Form(com.enonic.xp.form.Form) PropertyTree(com.enonic.xp.data.PropertyTree) 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