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));
}
}
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"));
}
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());
}
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);
}
}
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);
}
}
Aggregations