Search in sources :

Example 16 with Input

use of com.enonic.xp.form.Input 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 17 with Input

use of com.enonic.xp.form.Input 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 18 with Input

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

the class MixinServiceImplTest method testInlineFormItems_input.

@Test
public void testInlineFormItems_input() {
    initializeApps();
    final Form form = Form.create().addFormItem(Input.create().name("my_input").label("Input").inputType(InputTypeName.TEXT_LINE).build()).addFormItem(InlineMixin.create().mixin("myapp2:mixin2").build()).build();
    final Form transformedForm = service.inlineFormItems(form);
    final Input mixedInInput = transformedForm.getInput("input1");
    assertNotNull(mixedInInput);
    assertEquals("input1", mixedInInput.getPath().toString());
    assertEquals(InputTypeName.TEXT_LINE, mixedInInput.getInputType());
    assertEquals("myHelpText", mixedInInput.getHelpText());
}
Also used : Input(com.enonic.xp.form.Input) Form(com.enonic.xp.form.Form) Test(org.junit.jupiter.api.Test) AbstractSchemaTest(com.enonic.xp.core.impl.schema.AbstractSchemaTest)

Example 19 with Input

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

the class FormJsonToPropertyTreeTranslator method mapValue.

private void mapValue(final PropertySet parent, final String key, final JsonNode value) {
    final Property parentProperty = parent.getProperty();
    final Input input = getInput(parentProperty, key);
    if (input == null) {
        if (this.strictMode && !isOptionSetSelection(key, parentProperty)) {
            throw new IllegalArgumentException("No mapping defined for property " + key + " with value " + resolveStringValue(value));
        }
        parent.addProperty(key, resolveCoreValue(value));
    } else {
        final InputType type = this.inputTypeResolver.resolve(input.getInputType());
        final Value mappedPropertyValue = type.createValue(resolveCoreValue(value), input.getInputTypeConfig());
        parent.addProperty(key, mappedPropertyValue);
    }
}
Also used : Input(com.enonic.xp.form.Input) InputType(com.enonic.xp.inputtype.InputType) Value(com.enonic.xp.data.Value) Property(com.enonic.xp.data.Property)

Example 20 with Input

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

the class JsonToPropertyTreeTranslator method mapValue.

private void mapValue(final PropertySet parent, final String key, final JsonNode value) {
    final Property parentProperty = parent.getProperty();
    final Input input = getInput(parentProperty, key);
    if (input == null) {
        if (this.strictMode) {
            throw new IllegalArgumentException("No mapping defined for property " + key + " with value " + resolveStringValue(value));
        }
        parent.addProperty(key, resolveCoreValue(value));
    } else {
        final InputType type = this.inputTypeResolver.resolve(input.getInputType());
        final Value mappedPropertyValue = type.createValue(resolveCoreValue(value), input.getInputTypeConfig());
        parent.addProperty(key, mappedPropertyValue);
    }
}
Also used : Input(com.enonic.xp.form.Input) InputType(com.enonic.xp.inputtype.InputType) Value(com.enonic.xp.data.Value) Property(com.enonic.xp.data.Property)

Aggregations

Input (com.enonic.xp.form.Input)62 Test (org.junit.jupiter.api.Test)47 Value (com.enonic.xp.data.Value)24 Form (com.enonic.xp.form.Form)15 PropertyTree (com.enonic.xp.data.PropertyTree)11 FormItem (com.enonic.xp.form.FormItem)9 FormItemSet (com.enonic.xp.form.FormItemSet)9 FormDefaultValuesProcessor (com.enonic.xp.form.FormDefaultValuesProcessor)7 ContentType (com.enonic.xp.schema.content.ContentType)7 FormOptionSet (com.enonic.xp.form.FormOptionSet)5 FieldSet (com.enonic.xp.form.FieldSet)4 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)4 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)4 Property (com.enonic.xp.data.Property)3 Occurrences (com.enonic.xp.form.Occurrences)3 Content (com.enonic.xp.content.Content)2 ExtraData (com.enonic.xp.content.ExtraData)2 ValidationErrors (com.enonic.xp.content.ValidationErrors)2 PropertyPath (com.enonic.xp.data.PropertyPath)2 PropertySet (com.enonic.xp.data.PropertySet)2