public interface DynamicField<F extends DynamicField<F>> extends Field<F>
Represents the metadata for a FieldTypes.DYNAMIC
field. A dynamic field is useful for
situations where you have a property that might be managed with different metadata depending on
the form state.
A dynamic field can be used to switch between one field type and another, for example:
Fields.dynamic() .configureFields(fields -> { // match when "type" property is "TEXT_AREA" fields.add(Fields.textArea() .label("Text Area") .conditional(Conditional.when("type").equalTo(FieldTypes.TEXT_AREA))); // match when "type" property is "HTML" fields.add(Fields.html() .label("HTML") .conditional(Conditional.when("type").equalTo(FieldTypes.HTML))); // match when none of the others match, i.e. the default fields.add(Fields.string() .label("String")); return fields; });
A dynamic field can be used to switch read-only status for a field, for example:
Fields.dynamic() .configureFields(fields -> { // match when "mutable" property is true fields.add(Fields.string() .label("Text (immutable)") .readOnly() .conditional(Conditional.when("mutable").equalTo(true))); // match when none of the others match, i.e. the default fields.add(Fields.string() .label("Text (mutable)")); return fields; });
A dynamic field can be configured to clear the existing value when a new field is matched, for example:
Fields.dynamic() .clearValueOnMatch() // configure the field to clear the value on match .configureFields(fields -> { // match when "type" is COLOR fields.add(Fields.select() .label("Colors") .multi() .options(ColorOptionEnum.toOptions()) .conditional(Conditional.when("type").equalTo("COLOR"))); // match when "type" is SIZE fields.add(Fields.select() .label("Sizes") .multi() .options(SizeOptionEnum.toOptions()) .conditional(Conditional.when("type").equalTo("SIZE"))); // match when none of the others match, i.e. the default fields.add(Fields.stringArray() .label("Values")); return fields; });
Modifier and Type | Interface and Description |
---|---|
static class |
DynamicField.Attributes |
static class |
DynamicField.Helpers |
static class |
DynamicField.Keys |
Modifier and Type | Method and Description |
---|---|
default F |
clearValueOnMatch()
Configure this dynamic field to clear the existing value when a new field is matched.
|
default F |
configureFields(UnaryOperator<List<Field<?>>> fn)
Configure the list of fields this component will match against in deciding which field to
render.
|
default F |
name(String name) |
default F |
notClearValueOnMatch()
Configure this dynamic field to not clear the existing value when a new field is matched.
|
decorated, defaultValue, getDefaultValue, getName, getPlaceholder, getRequiredMessage, getValidationSchema, isReadOnly, isRequired, isShowInQueryBuilder, notReadOnly, notRequired, placeholder, placeholder, readOnly, readOnly, required, required, required, required, requiredMessage, requiredMessage, setDefaultValue, setName, setPlaceholder, setReadOnly, setRequired, setRequiredMessage, setShowInQueryBuilder, setValidationSchema, validationMethod, validationSchema, validationSchema
getHelpText, getHint, getTooltip, helpText, helpText, hidden, hidden, hint, hint, isHidden, notHidden, setHelpText, setHidden, setHint, setTooltip, tooltip, tooltip
addAction, addAction, addComponent, addEndpoint, addEndpoint, apply, attribute, augmentationKey, classifier, clearConditionals, clearEndpoints, conditional, conditionals, description, description, findAction, findAction, findActions, findAttribute, findComponent, findComponent, findComponents, findEndpoint, findEndpoint, findEndpoints, get, get, getAction, getAction, getActions, getActionsList, getAttribute, getAttribute, getAttributes, getAugmentationKey, getClassifier, getComponent, getComponent, getComponents, getComponentsList, getConditionals, getDescription, getEndpoint, getEndpoint, getEndpoints, getEndpointsList, getId, getLabel, getOrder, getScope, getType, hasAction, hasAttribute, hasComponent, hasEndpoint, id, isAugmentable, isTranslatable, label, label, notTranslatable, order, removeAction, removeAttribute, removeComponent, removeEndpoint, scope, self, setActions, setAttributes, setAugmentationKey, setClassifier, setComponents, setConditionals, setDescription, setEndpoints, setId, setLabel, setOrder, setScope, setTranslatable, setType, translatable, translatable, type
compareTo
default F configureFields(UnaryOperator<List<Field<?>>> fn)
List
of Field
which can be modified to configure the
list of components. The list returned will be sorted according to the order of the members.
Each member will be mapped over to the dynamic field's components map using
DynamicField.Keys.getFieldKey(int)
as the key.fn
- the function to configure the listdefault F clearValueOnMatch()
default F notClearValueOnMatch()
Copyright © 2021. All rights reserved.