Search in sources :

Example 1 with FormDefaultValuesProcessor

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

the class FormDefaultValuesProcessorImplTest method testOptionSetIsNotDefaultedForUnselected.

@Test
public void testOptionSetIsNotDefaultedForUnselected() {
    FormOptionSet.Builder myOptionSet = FormOptionSet.create().required(false).name("myOptionSet").occurrences(Occurrences.create(1, 1));
    FormOptionSetOption.Builder option1 = FormOptionSetOption.create().name("option1").defaultOption(true);
    FormOptionSetOption.Builder option2 = FormOptionSetOption.create().name("option2");
    option1.addFormItem(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "default").build()).build()).build());
    option2.addFormItem(Input.create().name("myDouble").label("double").inputType(InputTypeName.DOUBLE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "0").build()).build()).build());
    myOptionSet.addOptionSetOption(option1.build());
    myOptionSet.addOptionSetOption(option2.build());
    final Form form = Form.create().addFormItem(myOptionSet.build()).build();
    final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
    final PropertyTree data = new PropertyTree();
    defaultValuesProcessor.setDefaultValues(form, data);
    assertEquals("default", data.getString("myOptionSet.option1.myInput"));
    assertNull(data.getDouble("myOptionSet.option1.myDouble"));
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) Form(com.enonic.xp.form.Form) FormDefaultValuesProcessor(com.enonic.xp.form.FormDefaultValuesProcessor) PropertyTree(com.enonic.xp.data.PropertyTree) FormOptionSetOption(com.enonic.xp.form.FormOptionSetOption) Test(org.junit.jupiter.api.Test)

Example 2 with FormDefaultValuesProcessor

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

the class FormDefaultValuesProcessorImplTest method defaultValue_string_nonEmptyData.

@Test
public void defaultValue_string_nonEmptyData() {
    Input input = Input.create().name("testInput").label("testInput").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "two").build()).build()).build();
    final Form form = Form.create().addFormItem(input).build();
    final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
    final PropertyTree data = new PropertyTree();
    data.setProperty(PropertyPath.from("testInput"), ValueFactory.newString("three"));
    defaultValuesProcessor.setDefaultValues(form, data);
    assertEquals("three", data.getString("testInput"));
}
Also used : Input(com.enonic.xp.form.Input) Form(com.enonic.xp.form.Form) FormDefaultValuesProcessor(com.enonic.xp.form.FormDefaultValuesProcessor) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 3 with FormDefaultValuesProcessor

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

the class FormDefaultValuesProcessorImplTest method testDefaultValueForInputWithOccurrences.

@Test
public void testDefaultValueForInputWithOccurrences() {
    Input input = Input.create().name("testInput").label("testInput").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "Default Value").build()).build()).occurrences(Occurrences.create(3, 3)).build();
    final Form form = Form.create().addFormItem(input).build();
    final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
    final PropertyTree data = new PropertyTree();
    defaultValuesProcessor.setDefaultValues(form, data);
    for (int i = 0; i < 3; i++) {
        assertEquals("Default Value", data.getString("testInput", i));
    }
}
Also used : Input(com.enonic.xp.form.Input) Form(com.enonic.xp.form.Form) FormDefaultValuesProcessor(com.enonic.xp.form.FormDefaultValuesProcessor) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 4 with FormDefaultValuesProcessor

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

the class FormDefaultValuesProcessorImplTest method testDefaultValueForInputAndItemSetWithOccurrences.

@Test
public void testDefaultValueForInputAndItemSetWithOccurrences() {
    Input input = Input.create().name("testInput").label("testInput").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "Default Value").build()).build()).build();
    FormItemSet formItemSet = FormItemSet.create().name("field").label("field").addFormItem(input).occurrences(Occurrences.create(3, 3)).build();
    final Form form = Form.create().addFormItem(formItemSet).build();
    final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
    final PropertyTree data = new PropertyTree();
    defaultValuesProcessor.setDefaultValues(form, data);
    for (int i = 0; i < 3; i++) {
        assertEquals("Default Value", data.getProperty("field", i).getSet().getString("testInput"));
    }
}
Also used : Input(com.enonic.xp.form.Input) Form(com.enonic.xp.form.Form) FormDefaultValuesProcessor(com.enonic.xp.form.FormDefaultValuesProcessor) PropertyTree(com.enonic.xp.data.PropertyTree) FormItemSet(com.enonic.xp.form.FormItemSet) Test(org.junit.jupiter.api.Test)

Example 5 with FormDefaultValuesProcessor

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

the class FormDefaultValuesProcessorImplTest method testFieldSet.

@Test
public void testFieldSet() {
    FieldSet.Builder fieldSet = FieldSet.create().name("fieldSet").label("FieldSet").addFormItem(InlineMixin.create().mixin("testApp:testMixin").build()).addFormItem(Input.create().name("testInput").label("testInput").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "Default Value").build()).build()).build()).addFormItem(Input.create().name("testInput2").label("testInput2").inputType(InputTypeName.TEXT_LINE).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "Default Value 2").build()).build()).build());
    FormItemSet.Builder itemSet = FormItemSet.create().name("item-set").label("Item Set").occurrences(Occurrences.create(1, 1)).addFormItem(fieldSet.build());
    final Form form = Form.create().addFormItem(itemSet.build()).build();
    final FormDefaultValuesProcessor defaultValuesProcessor = new FormDefaultValuesProcessorImpl();
    final PropertyTree data = new PropertyTree();
    defaultValuesProcessor.setDefaultValues(form, data);
    assertEquals("Default Value", data.getString("item-set.testInput"));
    assertEquals("Default Value 2", data.getString("item-set.testInput2"));
}
Also used : FieldSet(com.enonic.xp.form.FieldSet) Form(com.enonic.xp.form.Form) FormDefaultValuesProcessor(com.enonic.xp.form.FormDefaultValuesProcessor) PropertyTree(com.enonic.xp.data.PropertyTree) FormItemSet(com.enonic.xp.form.FormItemSet) Test(org.junit.jupiter.api.Test)

Aggregations

PropertyTree (com.enonic.xp.data.PropertyTree)17 Form (com.enonic.xp.form.Form)17 FormDefaultValuesProcessor (com.enonic.xp.form.FormDefaultValuesProcessor)17 Test (org.junit.jupiter.api.Test)16 FormItemSet (com.enonic.xp.form.FormItemSet)7 Input (com.enonic.xp.form.Input)7 FormOptionSet (com.enonic.xp.form.FormOptionSet)6 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)6 Property (com.enonic.xp.data.Property)1 PropertySet (com.enonic.xp.data.PropertySet)1 FieldSet (com.enonic.xp.form.FieldSet)1 InputTypeProperty (com.enonic.xp.inputtype.InputTypeProperty)1