Hide Show field condition - 10quality/wpmvc-addon-administrator GitHub Wiki
Use the field option show_if
or hide_if
to add a condition to the field.
Show If
// Namespace and use statement...
class Settings extends Model
{
// Class properties...
protected function init()
{
// Other properties...
$this->tabs = [
'tab_id' => [
'fields' => [
'my_select' => [
'type' => 'select',
'title' => __( 'My select', 'my-domain' ),
'options' => [
'a' => __( 'Option A', 'my-domain' ),
'b' => __( 'Option B', 'my-domain' ),
'c' => __( 'Option C', 'my-domain' ),
'd' => __( 'Option C', 'my-domain' ),
],
],
'image' => [
'type' => 'media',
'title' => __( 'Image' ),
'show_if' => [
'my_select' => ['c', 'a'],
],
],
'resolutions' => [
'type' => 'repeater_open',
'show_if' => [
'.custom-css' => 'b',
],
],
// Other fields...
],
],
];
}
}
The show_if
holds a list of field IDs or DOM selectors that will act as condition rules to determine when a field should be visible.
Hide If
// Namespace and use statement...
class Settings extends Model
{
// Class properties...
protected function init()
{
// Other properties...
$this->tabs = [
'tab_id' => [
'fields' => [
'my_select' => [
'type' => 'select',
'title' => __( 'My select', 'my-domain' ),
'options' => [
'a' => __( 'Option A', 'my-domain' ),
'b' => __( 'Option B', 'my-domain' ),
'c' => __( 'Option C', 'my-domain' ),
'd' => __( 'Option C', 'my-domain' ),
],
],
'image' => [
'type' => 'media',
'title' => __( 'Image' ),
'hide_if' => [
'my_select' => ['b', 'd'],
],
],
'resolutions' => [
'type' => 'repeater_open',
'hide_if' => [
'#html-selector' => 'a',
],
],
// Other fields...
],
],
];
}
}
The hide_if
holds a list of field IDs or DOM selectors that will act as condition rules to determine when a field should be invisible.