Interface DynamicField<F extends DynamicField<F>>
- All Superinterfaces:
Comparable<F>
,Component<F>
,Copyable<F>
,Field<F>
,FormComponent<F>
,Serializable
- All Known Implementing Classes:
DefaultDynamicField
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; });
- Author:
- Nick Crum (ncrum)
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final class
static final class
static final class
-
Method Summary
Modifier and TypeMethodDescriptiondefault F
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
default F
Configure this dynamic field to not clear the existing value when a new field is matched.Methods inherited from interface java.lang.Comparable
compareTo
Methods inherited from interface com.broadleafcommerce.metadata.dsl.core.Component
addAction, addAction, addComponent, addEndpoint, addEndpoint, apply, attribute, augmentationKey, classifier, clearConditionals, clearEndpoints, conditional, conditionals, description, description, findAction, findAction, findActions, findAttribute, findAttribute, findComponent, findComponent, findComponents, findEndpoint, 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
Methods inherited from interface com.broadleafcommerce.metadata.dsl.core.Field
clearReadOnlyConditionals, decorated, decorated, defaultValue, getDefaultValue, getName, getPlaceholder, getReadOnlyConditionals, getRequiredMessage, getValidationSchema, isReadOnly, isRequired, isShowInQueryBuilder, isTargetCollection, notReadOnly, notRequired, placeholder, placeholder, readOnly, readOnly, readOnlyConditional, readOnlyConditionals, required, required, required, required, requiredMessage, requiredMessage, setDefaultValue, setName, setPlaceholder, setReadOnly, setReadOnlyConditionals, setRequired, setRequiredMessage, setShowInQueryBuilder, setValidationSchema, targetIsCollection, targetIsNotCollection, validationMethod, validationSchema, validationSchema
Methods inherited from interface com.broadleafcommerce.metadata.dsl.core.FormComponent
getHelpText, getHint, getTooltip, helpText, helpText, helpText, hidden, hidden, hint, hint, isHidden, notHidden, setHelpText, setHidden, setHint, setTooltip, tooltip, tooltip
-
Method Details
-
name
- Specified by:
name
in interfaceField<F extends DynamicField<F>>
-
configureFields
Configure the list of fields this component will match against in deciding which field to render. This provides aList
ofField
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 usingDynamicField.Keys.getFieldKey(int)
as the key.- Parameters:
fn
- the function to configure the list- Returns:
- this
-
clearValueOnMatch
Configure this dynamic field to clear the existing value when a new field is matched. This will result in the property the field targets being cleared out and then defaulted to a new value if the matched field has a default value.- Returns:
- this
-
notClearValueOnMatch
Configure this dynamic field to not clear the existing value when a new field is matched. This is the default behavior of dynamic fields, and the result is that the existing property value is preserved even when new fields are matched.- Returns:
- this
-