Class FormlyBuilder<T extends FormlyBuilder<T>>

java.lang.Object
io.openems.edge.core.appmanager.formly.builder.FormlyBuilder<T>
All Implemented Interfaces:
OnlyIf<T>, Self<T>
Direct Known Subclasses:
CheckboxBuilder, DateTimeBuilder, FieldGroupBuilder, InputBuilder, RangeBuilder, ReorderArrayBuilder, RepeatBuilder, SelectBuilder, SelectGroupBuilder, TextBuilder

public abstract class FormlyBuilder<T extends FormlyBuilder<T>> extends Object implements OnlyIf<T>, Self<T>
A Builder for a Formly field.
 {
        "key": "key",
        "type": "input",
        "templateOptions": {
                "label": "label",
                "required": true
        },
        "expressionProperties": {
                "templateOptions.required": "model.PROPERTY"
        },
        "hideExpression": "!model.PROPERTY",
        "defaultValue": "defaultValue",
  "wrappers": []Wrappers
 }
 
  • Field Details

    • jsonObject

      protected final com.google.gson.JsonObject jsonObject
    • templateOptions

      protected final com.google.gson.JsonObject templateOptions
  • Constructor Details

    • FormlyBuilder

      protected FormlyBuilder(Nameable property)
  • Method Details

    • setKey

      public final T setKey(String key)
    • setDefaultValue

      public final T setDefaultValue(String defaultValue)
    • setDefaultValue

      public final T setDefaultValue(Boolean defaultValue)
    • setDefaultValue

      public final T setDefaultValue(Number defaultValue)
    • setDefaultValue

      public final T setDefaultValue(com.google.gson.JsonElement defaultValue)
    • setDefaultValueWithStringSupplier

      public final T setDefaultValueWithStringSupplier(Supplier<String> supplieDefaultValue)
    • setDefaultValueWithBooleanSupplier

      public final T setDefaultValueWithBooleanSupplier(Supplier<Boolean> supplieDefaultValue)
    • getDefaultValue

      public final com.google.gson.JsonElement getDefaultValue()
    • isRequired

      public final T isRequired(boolean isRequired)
      Sets if the input is required. Default: 'false'
      Parameters:
      isRequired - if the input is required
      Returns:
      this
    • setLabel

      public final T setLabel(String label)
    • setDescription

      public final T setDescription(String description)
    • onlyShowIf

      public final T onlyShowIf(BooleanExpression expression)
      Only shows the current input if the given
      invalid reference
      ExpressionBuilder
      returns true.
      Parameters:
      expression - the BooleanExpression to set
      Returns:
      this
    • hide

      public final T hide(boolean hide)
      Sets if input is hidden by default.
      Parameters:
      hide - true if the input should be hidden
      Returns:
      this
    • disabled

      public final T disabled(boolean disabled)
      Sets if input is disabled by default.
      Parameters:
      disabled - true if the input should be disabled
      Returns:
      this
    • readonly

      public final T readonly(boolean readonly)
      Sets if input is readonly.
      Parameters:
      readonly - true if the input should be readonly
      Returns:
      this
    • setLabelExpression

      public final T setLabelExpression(StringExpression expression)
    • setDefaultValueCases

      public final T setDefaultValueCases(DefaultValueOptions... defaultValueOptions)
    • hideKey

      public T hideKey()
      Hides the current key of the input. Results are all child inputs are not in the model as a JsonObject value of this key instead the are on the same level saved as this field.
      Returns:
      this
    • addWrapper

      public final T addWrapper(Wrappers wrapper)
      Adds a wrapper to the current input.
      Parameters:
      wrapper - the Wrappers to add
      Returns:
      this
    • setCustomValidation

      public T setCustomValidation(String name, BooleanExpression validationExpression, String errorMessage, Nameable propertyToShowError)
    • setCustomValidation

      public T setCustomValidation(String name, BooleanExpression validationExpression, StringExpression messageExpression, Nameable propertyToShowError)
      Sets a custom validation of the input.

      This sets a formly validation like explained in the formly documentation with the exception, that the validation is not directly passed as a function instead it needs to be a string which is converted into a validation function from the ui. If you want detailed information about how the string gets converted to a function in the ui have a look at the post process function here.

      Inside the string expression you have access to:

      • model: the current values
      • formState: the state of the form
      • field: the current field
      • control: the form control
      • initialModel: the initial model (only set when modifying an existing instance)
      Parameters:
      name - the name of the validation
      validationExpression - the expression of the validation
      messageExpression - the expression of the error message
      propertyToShowError - the path property to show the error message
      Returns:
      this
    • setCustomValidation

      public T setCustomValidation(String name, BooleanExpression validationExpression, String errorMessage)
    • build

      public com.google.gson.JsonObject build()
    • getType

      protected abstract String getType()
    • getExpressionProperties

      protected final com.google.gson.JsonObject getExpressionProperties()
    • getValidators

      protected final com.google.gson.JsonObject getValidators()
    • self

      public T self()
      Description copied from interface: Self
      Gets itself.
      Specified by:
      self in interface Self<T extends FormlyBuilder<T>>
      Returns:
      this