Search in sources :

Example 11 with FormOptionSet

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

the class InputValidationVisitorTest method validateOptionSetValid.

@Test
public void validateOptionSetValid() throws Exception {
    FormOptionSet formOptionSet = FormOptionSet.create().name("myOptionSet").label("My option set").helpText("Option set help text").addOptionSetOption(FormOptionSetOption.create().name("myOptionSetOption1").label("option label1").helpText("Option help text").addFormItem(Input.create().name("myTextLine1").label("myTextLine1").inputType(InputTypeName.TEXT_LINE).build()).build()).addOptionSetOption(FormOptionSetOption.create().name("myOptionSetOption2").label("option label2").helpText("Option help text").addFormItem(Input.create().name("myTextLine2").label("myTextLine2").inputType(InputTypeName.TEXT_LINE).build()).build()).build();
    Form form = Form.create().addFormItem(formOptionSet).build();
    PropertyTree propertyTree = new PropertyTree();
    propertyTree.setString("myOptionSet.myOptionSetOption1.myTextLine1", "33");
    final InputValidationVisitor validationVisitor = new InputValidationVisitor(propertyTree, InputTypes.BUILTIN);
    validationVisitor.traverse(form);
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) Form(com.enonic.xp.form.Form) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 12 with FormOptionSet

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

the class MixinServiceImpl method transformFormItems.

private List<FormItem> transformFormItems(final Iterable<FormItem> iterable, final Set<MixinName> inlineMixinStack) {
    final List<FormItem> formItems = new ArrayList<>();
    for (final FormItem formItem : iterable) {
        if (formItem instanceof InlineMixin) {
            final InlineMixin inline = (InlineMixin) formItem;
            final MixinName mixinName = inline.getMixinName();
            final Mixin mixin = getByName(mixinName);
            if (mixin != null) {
                if (inlineMixinStack.contains(mixinName)) {
                    final String error = "Cycle detected in mixin [" + mixin.getName() + "]. It contains an inline mixin that references itself.";
                    LOG.error(error);
                    throw new IllegalArgumentException(error);
                }
                inlineMixinStack.add(mixinName);
                final Form mixinForm = doInlineFormItems(mixin.getForm(), inlineMixinStack);
                inlineMixinStack.remove(mixinName);
                for (final FormItem mixinFormItem : mixinForm) {
                    formItems.add(mixinFormItem.copy());
                }
            } else {
                throw new IllegalArgumentException("Inline mixin [" + mixinName + "] not found");
            }
        } else if (formItem instanceof FormItemSet) {
            final FormItemSet.Builder formItemSetBuilder = FormItemSet.create((FormItemSet) formItem);
            formItemSetBuilder.clearFormItems();
            formItemSetBuilder.addFormItems(transformFormItems((FormItemSet) formItem, inlineMixinStack));
            formItems.add(formItemSetBuilder.build());
        } else if (formItem instanceof FieldSet) {
            final FieldSet.Builder formItemSetBuilder = FieldSet.create((FieldSet) formItem);
            formItemSetBuilder.clearFormItems();
            formItemSetBuilder.addFormItems(transformFormItems((FieldSet) formItem, inlineMixinStack));
            formItems.add(formItemSetBuilder.build());
        } else if (formItem instanceof FormOptionSet) {
            final FormOptionSet.Builder formOptionSetBuilder = FormOptionSet.create((FormOptionSet) formItem);
            formOptionSetBuilder.clearOptions();
            for (FormOptionSetOption option : (FormOptionSet) formItem) {
                final FormOptionSetOption.Builder optionBuilder = FormOptionSetOption.create(option);
                optionBuilder.clearFormItems();
                optionBuilder.addFormItems(transformFormItems(option.getFormItems(), inlineMixinStack));
                formOptionSetBuilder.addOptionSetOption(optionBuilder.build());
            }
            formItems.add(formOptionSetBuilder.build());
        } else {
            formItems.add(formItem.copy());
        }
    }
    return formItems;
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) Form(com.enonic.xp.form.Form) FormItem(com.enonic.xp.form.FormItem) ArrayList(java.util.ArrayList) FormOptionSetOption(com.enonic.xp.form.FormOptionSetOption) Mixin(com.enonic.xp.schema.mixin.Mixin) InlineMixin(com.enonic.xp.form.InlineMixin) MixinName(com.enonic.xp.schema.mixin.MixinName) FieldSet(com.enonic.xp.form.FieldSet) InlineMixin(com.enonic.xp.form.InlineMixin) FormItemSet(com.enonic.xp.form.FormItemSet)

Example 13 with FormOptionSet

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

the class ContentTypeHandlerTest method getForm.

private Form getForm() {
    Input myTextLine = Input.create().name("myTextLine").inputType(InputTypeName.TEXT_LINE).label("My text line").customText("Some custom text").helpText("Some help text").required(true).inputTypeConfig(InputTypeConfig.create().property(InputTypeProperty.create("regexp", "\\b\\d{3}-\\d{2}-\\d{4}\\b").build()).build()).build();
    Input myCustomInput = Input.create().name("myCheckbox").inputType(InputTypeName.CHECK_BOX).label("My checkbox input").required(false).defaultValue(InputTypeDefault.create().property(InputTypeProperty.create("default", "checked").build()).build()).build();
    final InputTypeProperty option1 = InputTypeProperty.create("option", "Option One").attribute("value", "one").build();
    final InputTypeProperty option2 = InputTypeProperty.create("option", "Option Two").attribute("value", "two").build();
    Input radioButtonInput = Input.create().name("myRadioButton").inputType(InputTypeName.RADIO_BUTTON).label("Radio button").inputTypeConfig(InputTypeConfig.create().property(option1).property(option2).build()).build();
    FieldSet myFieldSet = FieldSet.create().name("myFieldSet").label("My field set").addFormItem(Input.create().name("myTextLineInFieldSet").inputType(InputTypeName.TEXT_LINE).label("My text line").required(false).build()).build();
    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();
    final FormOptionSet formOptionSet = FormOptionSet.create().name("myOptionSet").label("My option set").helpText("Option set help text").addOptionSetOption(FormOptionSetOption.create().name("myOptionSetOption1").label("option label1").helpText("Option help text").addFormItem(Input.create().name("myTextLine1").label("myTextLine1").inputType(InputTypeName.TEXT_LINE).build()).build()).addOptionSetOption(FormOptionSetOption.create().name("myOptionSetOption2").label("option label2").helpText("Option help text").addFormItem(Input.create().name("myTextLine2").label("myTextLine2").inputType(InputTypeName.TEXT_LINE).build()).build()).build();
    return Form.create().addFormItem(myTextLine).addFormItem(myCustomInput).addFormItem(radioButtonInput).addFormItem(myFieldSet).addFormItem(myFormItemSet).addFormItem(formOptionSet).build();
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) Input(com.enonic.xp.form.Input) FieldSet(com.enonic.xp.form.FieldSet) InputTypeProperty(com.enonic.xp.inputtype.InputTypeProperty) FormItemSet(com.enonic.xp.form.FormItemSet)

Aggregations

FormOptionSet (com.enonic.xp.form.FormOptionSet)13 FormItemSet (com.enonic.xp.form.FormItemSet)8 Test (org.junit.jupiter.api.Test)6 Form (com.enonic.xp.form.Form)5 FormItem (com.enonic.xp.form.FormItem)5 Input (com.enonic.xp.form.Input)5 FieldSet (com.enonic.xp.form.FieldSet)4 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)4 ContentType (com.enonic.xp.schema.content.ContentType)3 PropertySet (com.enonic.xp.data.PropertySet)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 Occurrences (com.enonic.xp.form.Occurrences)2 AbstractSchemaTest (com.enonic.xp.core.impl.schema.AbstractSchemaTest)1 PropertyPath (com.enonic.xp.data.PropertyPath)1 FormItems (com.enonic.xp.form.FormItems)1 InlineMixin (com.enonic.xp.form.InlineMixin)1 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)1 InputTypeProperty (com.enonic.xp.inputtype.InputTypeProperty)1 Mixin (com.enonic.xp.schema.mixin.Mixin)1 MixinName (com.enonic.xp.schema.mixin.MixinName)1