-
Notifications
You must be signed in to change notification settings - Fork 1
Field dependency
Truong Giang edited this page Sep 20, 2017
·
1 revision
Field dependency allows you create relationship between fields to control visibility of one field based on others value. With PuppyFW, you can easily create field dependency by adding dependency
attribute to field definition:
array(
'id' => 'human',
'title' => 'Are you a human?',
'type' => 'checkbox',
),
array(
'id' => 'name',
'title' => 'Type your name',
'type' => 'text',
'dependency' => array( 'human', '==', true ),
),
In above example, field name
will be visible if field human
is checked.
- The first element is ID of field which this field depends on.
- The second element is the operator, accepts:
==
,>
,>=
,<
,<=
,!=
,NOT EMPTY
,IN
,NOT IN
,CONTAIN
,NOT CONTAIN
. - The third element is the value to compare.
Note:
- If you use
EMPTY
orNOT EMPTY
operator, the third element is unnecessary. - If you use
IN
orNOT IN
operator, the third element should be an array. - If you use
CONTAIN
orNOT CONTAIN
operator, the value of depended field should be array. - If a field depends on another field in a group, the first element must follow this structure:
group_id---nested_group_1_id---...---field_id
. - Dependency for repeatable field is limited.
A field can have multiple dependencies by pass an array of dependencies to dependency
attribute:
array(
'id' => 'human',
'title' => 'Are you a human?',
'type' => 'checkbox',
),
array(
'id' => 'has_name',
'title' => 'Do you have a name?',
'type' => 'checkbox',
'dependency' => array( 'human', '==', true ),
),
array(
'id' => 'name',
'title' => 'What is your name?',
'type' => 'text',
'dependency' => array(
array( 'human', '==', true ),
array( 'has_name', '==', true ),
),
),
In above example, field has_name
only shows if human
is checked. Field name
only shows if both human
and has_name
are checked.
At the moment, the relationship between dependencies is AND
. OR
relationship will be included in the future.