Usage
The HTML and JavaScript tabs build the identical Form Builder setup shown above,
declaratively via attributes or imperatively via the JS API. A FieldRole
marks a field for special handling elsewhere in your app once the definition is saved. The
Price field above already has the Price Field role assigned, restricted to NumericBox
fields via inputType, so wherever this saved definition gets processed later,
that field can be picked out by its role rather than by name, regardless of what the
person building the form happened to call it.
<cui-form id="form"
ui-display-mode="2"
ui-fixed-layout="false"
ui-field-roles='[
{ "id": "Price", "label": "Price Field", "inputType": 6 }
]'
ui-field-sets='[
{ "type": "FieldSet", "label": "Product", "fields": [
{ "type": "Field", "name": "productName", "label": "Product Name" },
{ "type": "Field", "name": "price", "label": "Price", "inputType": 6, "role": "Price" },
{ "type": "Field", "name": "inStock", "label": "In Stock", "inputType": 2 }
] }
]'></cui-form>
const form = $UI.createComponent(componyx.UI.Form, {
id: 'form',
displayMode: componyx.UI.Form.DisplayModeOption.BUILD,
fixedLayout: false,
fieldRoles: [
new componyx.UI.Form.FieldRole({ id: 'Price', label: 'Price Field', inputType: componyx.UI.Form.InputTypeOption.NUMERICBOX })
],
fieldSets: [
new componyx.UI.Form.FieldSet({
label: 'Product',
fields: [
new componyx.UI.Form.Field({ name: 'productName', label: 'Product Name' }),
new componyx.UI.Form.Field({
name: 'price',
label: 'Price',
inputType: componyx.UI.Form.InputTypeOption.NUMERICBOX,
role: 'Price'
}),
new componyx.UI.Form.Field({
name: 'inStock',
label: 'In Stock',
inputType: componyx.UI.Form.InputTypeOption.CHECKBOX
})
]
})
],
containerElement: document.body
});
form.show();