Search in sources :

Example 51 with Form

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

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

the class OccurrenceValidatorTest method testOptionSetWithUnlimitedNumberAllowedSelections.

@Test
public void testOptionSetWithUnlimitedNumberAllowedSelections() {
    Form form = Form.create().addFormItem(FormOptionSet.create().name("options").label("Option tests").multiselection(Occurrences.create(0, 0)).occurrences(Occurrences.create(1, 1)).addOptionSetOption(FormOptionSetOption.create().name("a").label("A").build()).addOptionSetOption(FormOptionSetOption.create().name("b").label("B").build()).build()).build();
    ContentType contentType = ContentType.create().name("myapplication:my_type").superType(ContentTypeName.structured()).form(form).build();
    Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
    PropertySet propertySet = new PropertySet();
    propertySet.setProperty("a", ValueFactory.newString("Value A"));
    propertySet.setProperty("b", ValueFactory.newString("Value B"));
    content.getData().setSet("options", propertySet);
    final ValidationErrors validationResults = validate(content);
    assertFalse(validationResults.hasErrors());
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) Form(com.enonic.xp.form.Form) ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 53 with Form

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

the class BuiltinMacroDescriptors method generateDisableMacroDescriptor.

private MacroDescriptor generateDisableMacroDescriptor() {
    final MacroKey macroKey = MacroKey.from(ApplicationKey.SYSTEM, "disable");
    final Form form = Form.create().addFormItem(createTextAreaInput("body", "Contents", macroKey).occurrences(1, 1).build()).build();
    return create(macroKey, "Disable macros", "Contents of this macro will not be formatted", form);
}
Also used : MacroKey(com.enonic.xp.macro.MacroKey) Form(com.enonic.xp.form.Form)

Example 54 with Form

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

the class BuiltinMacroDescriptors method generateEmbedIFrameMacroDescriptor.

private MacroDescriptor generateEmbedIFrameMacroDescriptor() {
    final MacroKey macroKey = MacroKey.from(ApplicationKey.SYSTEM, "embed");
    final Form form = Form.create().addFormItem(createTextAreaInput("body", "IFrame HTML", macroKey).occurrences(1, 1).build()).build();
    return create(macroKey, "Embed IFrame", "Generic iframe embedder", form);
}
Also used : MacroKey(com.enonic.xp.macro.MacroKey) Form(com.enonic.xp.form.Form)

Example 55 with Form

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

the class AbstractCommand method doTransformInlineMixins.

private ContentTypes doTransformInlineMixins(final ContentTypes contentTypes) {
    final ContentTypes.Builder transformedContentTypes = ContentTypes.create();
    for (final ContentType contentType : contentTypes) {
        final Form transformedForm = mixinService.inlineFormItems(contentType.getForm());
        final ContentType transformedCty = ContentType.create(contentType).form(transformedForm).build();
        transformedContentTypes.add(transformedCty);
    }
    return transformedContentTypes.build();
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) Form(com.enonic.xp.form.Form) ContentTypes(com.enonic.xp.schema.content.ContentTypes)

Aggregations

Form (com.enonic.xp.form.Form)79 Test (org.junit.jupiter.api.Test)59 PropertyTree (com.enonic.xp.data.PropertyTree)36 FormDefaultValuesProcessor (com.enonic.xp.form.FormDefaultValuesProcessor)17 Input (com.enonic.xp.form.Input)17 FormItemSet (com.enonic.xp.form.FormItemSet)13 FormOptionSet (com.enonic.xp.form.FormOptionSet)11 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)10 ContentType (com.enonic.xp.schema.content.ContentType)8 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)7 AbstractSchemaTest (com.enonic.xp.core.impl.schema.AbstractSchemaTest)5 PropertySet (com.enonic.xp.data.PropertySet)5 Content (com.enonic.xp.content.Content)4 CreateContentParams (com.enonic.xp.content.CreateContentParams)4 EditableContent (com.enonic.xp.content.EditableContent)4 MacroKey (com.enonic.xp.macro.MacroKey)4 XData (com.enonic.xp.schema.xdata.XData)4 SiteConfigs (com.enonic.xp.site.SiteConfigs)4 ContentPath (com.enonic.xp.content.ContentPath)3 Page (com.enonic.xp.page.Page)3