Skip to content

Component Linkage

Implement component linkage in forms—for example, showing or hiding components based on input values. FormCreate provides component linkage functionality to control component states like display, disabled, and required through the control configuration option.

Note

In the Pro version, use data linkage and logical condition configuration instead of the basic component linkage solution. Detailed Documentation.

control3

Data Structure

ts
type Control =  Array<{
  // Control through built-in conditions, mutually exclusive with `handle`
  value?: any;
  // Built-in conditions, can be combined with `value`
  condition?: '==' | '!=' | '<>' | '>' | '>=' | '<' | '<=' | 'in' | 'notIn' | 'on' | 'notOn' | 'between' | 'notBetween' | 'empty' | 'notEmpty';
  // Custom control condition
  handle?: (val: any, api: Api) => boolean;
  // Control the display, disabled, required state of corresponding rules. Default value is if
  method?: 'if' | 'enabled' | 'required';
  // Controlled fields (corresponding component field IDs or identifiers)
  rule: string[];
}>

Note: Component values must be strictly equal to value (including complete data type consistency).

method Options

KeyConfigurationDescription
ifConditional RenderingControl component's show/hide state
requiredRequired ValidationSet whether field is required
disabledDisabled StateControl whether component is interactive

condition Options

KeyOperatorDescriptionValue TypeExample
==Strict EqualComponent value exactly equals valueAnyvalue: 10
!=Not EqualComponent value does not equal valueAnyvalue: "error"
<>Not EqualComponent value does not equal value (same as !=)Anyvalue: false
>Greater ThanComponent value is greater than valueNumbervalue: 100
>=Greater Than or EqualComponent value is greater than or equal to valueNumbervalue: 18
<Less ThanComponent value is less than valueNumbervalue: 0
<=Less Than or EqualComponent value is less than or equal to valueNumbervalue: 100
inContainsComponent value exists in value arrayArrayvalue: [1,2,3]
notInDoes Not ContainComponent value does not exist in value arrayArrayvalue: ["a","b"]
onContains Valuevalue exists in component value (array)StringNumber
notOnDoes Not Contain Valuevalue does not exist in component value (array)StringNumber
betweenWithin RangeComponent value is between value[0] and value[1]Array[2]value: [10,20]
notBetweenOutside RangeComponent value is not between value[0] and value[1]Array[2]value: [0,100]
emptyEmptyPass validation when component value is empty-value: true
notEmptyNot EmptyPass validation when component value is not empty-value: true
patternRegular ExpressionValidate component value with regular expressionStringvalue:'^1\d{10}$' (no "/" before and after)

Linkage Example

Implement linkage display between phone number (Ffb7m8y7e77zalc) and verification code (Ffa7m8y7eu9eaoc) fields: only show the verification code input when the phone number input is not empty.

control

Configure linkage rules in linkage data:

control2

Note: Configure strictly according to the specified data type, otherwise it will trigger content syntax error prompts.

More Examples

Control Component Display State

Control the display state of specific fields (e.g., field1, field2) through configuration rules. When the condition is met (e.g., value is '1'), these fields are dynamically shown or hidden:

js
[{
    value: '1',
    rule: ['field1', 'field2']
}]

Control Component Disabled State

Control the disabled state of specific components (e.g., field1, name2) through configuration rules. When the condition is met (e.g., value is '1'), these fields are dynamically enabled or disabled:

js
[{
    value: '1',
    method: 'disabled',
    rule: ['field1', 'name2']
}]

Control Component Required State

Control the required state of specific fields (e.g., field1) through configuration rules. When the condition is met (e.g., value is '1'), the required validation rule is dynamically set or removed:

ts
[{
    value: '1',
    method: 'required',
    rule: ['field1']
}]

Calculate Component Display State

Use custom functions to control field display conditions. The handle method determines if the field value is 'ok' or 'no', dynamically controlling the show/hide state:

js
[{
  "handle": function(val, api) {
    return val === 'ok' || val === 'no';
  },
  "method": "if",
  "rule": ["Ffa7m8y7eu9eaoc"]
}]