Search in sources :

Example 11 with Form

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

the class XmlPageDescriptorParserTest method assertResult.

private void assertResult() throws Exception {
    final PageDescriptor result = this.builder.build();
    assertEquals("myapplication:mypage", result.getKey().toString());
    assertEquals("mypage", result.getName());
    assertEquals("Landing page", result.getDisplayName());
    assertEquals("key.display-name", result.getDisplayNameI18nKey());
    assertEquals("My Page Description", result.getDescription());
    assertEquals("key.description", result.getDescriptionI18nKey());
    final Form config = result.getConfig();
    assertNotNull(config);
    assertEquals(InputTypeName.DOUBLE, config.getFormItem("pause").toInput().getInputType());
    assertEquals("Pause parameter", config.getFormItem("pause").toInput().getLabel());
    assertEquals("key1.label", config.getFormItem("pause").toInput().getLabelI18nKey());
    assertEquals("key1.help-text", config.getFormItem("pause").toInput().getHelpTextI18nKey());
    assertNotNull(config.getFormItem("myFormItemSet").toFormItemSet());
    assertEquals("My form item set", config.getFormItem("myFormItemSet").toFormItemSet().getLabel());
    assertEquals(InputTypeName.TEXT_LINE, config.getFormItem("myFormItemSet.fieldSetItem").toInput().getInputType());
    assertEquals("Field set Item", config.getFormItem("myFormItemSet.fieldSetItem").toInput().getLabel());
    assertEquals("key2.label", config.getFormItem("myFormItemSet.fieldSetItem").toInput().getLabelI18nKey());
    assertEquals("key2.help-text", config.getFormItem("myFormItemSet.fieldSetItem").toInput().getHelpTextI18nKey());
    final RegionDescriptors regions = result.getRegions();
    assertNotNull(regions);
    assertEquals(3, regions.numberOfRegions());
    assertNotNull(regions.getRegionDescriptor("header"));
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) Form(com.enonic.xp.form.Form) RegionDescriptors(com.enonic.xp.region.RegionDescriptors)

Example 12 with Form

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

the class XmlLayoutDescriptorParserTest method assertResult.

private void assertResult() throws Exception {
    final LayoutDescriptor result = this.builder.build();
    assertEquals("myapplication:mylayout", result.getKey().toString());
    assertEquals("mylayout", result.getName());
    assertEquals("My Layout", result.getDisplayName());
    assertEquals("key.display-name", result.getDisplayNameI18nKey());
    assertEquals("My Layout Description", result.getDescription());
    assertEquals("key.description", result.getDescriptionI18nKey());
    final Form config = result.getConfig();
    assertNotNull(config);
    assertEquals(InputTypeName.DOUBLE, config.getFormItem("pause").toInput().getInputType());
    assertEquals("Pause parameter", config.getFormItem("pause").toInput().getLabel());
    assertEquals("key1.label", config.getFormItem("pause").toInput().getLabelI18nKey());
    assertEquals("key1.help-text", config.getFormItem("pause").toInput().getHelpTextI18nKey());
    assertNotNull(config.getFormItem("myFormItemSet").toFormItemSet());
    assertEquals("My form item set", config.getFormItem("myFormItemSet").toFormItemSet().getLabel());
    assertEquals(InputTypeName.TEXT_LINE, config.getFormItem("myFormItemSet.fieldSetItem").toInput().getInputType());
    assertEquals("Field set Item", config.getFormItem("myFormItemSet.fieldSetItem").toInput().getLabel());
    assertEquals("key2.label", config.getFormItem("myFormItemSet.fieldSetItem").toInput().getLabelI18nKey());
    assertEquals("key2.help-text", config.getFormItem("myFormItemSet.fieldSetItem").toInput().getHelpTextI18nKey());
    final RegionDescriptors regions = result.getRegions();
    assertNotNull(regions);
    assertEquals(3, regions.numberOfRegions());
    assertNotNull(regions.getRegionDescriptor("header"));
}
Also used : LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) Form(com.enonic.xp.form.Form) RegionDescriptors(com.enonic.xp.region.RegionDescriptors)

Example 13 with Form

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

the class XmlPartDescriptorParserTest method assertResult.

private void assertResult() throws Exception {
    final PartDescriptor result = this.builder.build();
    assertEquals("myapplication:mypart", result.getKey().toString());
    assertEquals("mypart", result.getName());
    assertEquals("A Part", result.getDisplayName());
    assertEquals("key.display-name", result.getDisplayNameI18nKey());
    assertEquals("My Part Description", result.getDescription());
    assertEquals("key.description", result.getDescriptionI18nKey());
    final Form config = result.getConfig();
    assertNotNull(config);
    assertEquals(InputTypeName.DOUBLE, config.getFormItem("width").toInput().getInputType());
    assertEquals("Column width", config.getFormItem("width").toInput().getLabel());
    assertEquals("key.label", config.getFormItem("width").toInput().getLabelI18nKey());
    assertEquals("key.help-text", config.getFormItem("width").toInput().getHelpTextI18nKey());
    assertEquals("link-urls", config.getFormItem("link-urls").toInlineMixin().getName());
}
Also used : PartDescriptor(com.enonic.xp.region.PartDescriptor) Form(com.enonic.xp.form.Form)

Example 14 with Form

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

the class PageDefaultValuesProcessor method applyComponentDefaultValues.

private void applyComponentDefaultValues(final DescriptorBasedComponent cmp) {
    if (cmp.getDescriptor() == null) {
        return;
    }
    final Form cmpForm;
    if (cmp instanceof PartComponent) {
        final PartDescriptor partDescriptor = partDescriptorService.getByKey(cmp.getDescriptor());
        cmpForm = partDescriptor.getConfig();
    } else {
        final LayoutDescriptor layoutDescriptor = layoutDescriptorService.getByKey(cmp.getDescriptor());
        cmpForm = layoutDescriptor.getConfig();
    }
    if (cmpForm != null) {
        final PropertyTree cmpData = cmp.getConfig();
        formDefaultValuesProcessor.setDefaultValues(cmpForm, cmpData);
    }
}
Also used : LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) Form(com.enonic.xp.form.Form) PartDescriptor(com.enonic.xp.region.PartDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) PartComponent(com.enonic.xp.region.PartComponent)

Example 15 with Form

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

the class IndexConfigVisitorTest method top_htmlArea.

@Test
public void top_htmlArea() throws Exception {
    Input myTextLine = Input.create().name("htmlArea").inputType(InputTypeName.HTML_AREA).label("htmlArea").required(true).build();
    Form form = Form.create().addFormItem(myTextLine).build();
    final PatternIndexConfigDocument.Builder builder = PatternIndexConfigDocument.create();
    final IndexConfigVisitor validationVisitor = new IndexConfigVisitor("parent", builder);
    validationVisitor.traverse(form);
    final PatternIndexConfigDocument document = builder.build();
    assertEquals(1, document.getPathIndexConfigs().size());
    assertEquals("htmlStripper", document.getConfigForPath(PropertyPath.from("parent.htmlArea")).getIndexValueProcessors().get(0).getName());
}
Also used : Input(com.enonic.xp.form.Input) Form(com.enonic.xp.form.Form) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) Test(org.junit.jupiter.api.Test)

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