Support Forum
Hello, I have 2 fields of type text.
Each field is displayed using the Meta Box Conditional Logic.
How can I use validation in case the field 1 is filled it does not complain that field 2 has nothing? or on the contrary if I fill in field 2 do not complain that field 1 is empty?
Because I want to display a third field based on the condition above or field1 or field2 is filled.
Hi there,
Do you mean that the third field will be displayed when at least first or second field is not empty?
Thanks.
Hello Truong Giang, exactly the precise, display a third field only if field 1 or field 2 is with data.
Hey Infolu,
This can be achieve by using Compound Statements in Conditional Logic.
https://docs.metabox.io/extensions/meta-box-conditional-logic/#compound-statements
Here is my example, the field Address will visible when Full Name or Email has filled.
add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {
$meta_boxes[] = array(
'id' => 'personal',
'title' => 'Personal Information',
'post_types' => 'post',
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => 'Full Name',
'desc' => 'Full name',
'id' => 'name',
'type' => 'text',
),
array(
'name' => 'Email',
'desc' => 'Email Address',
'id' => 'email',
'type' => 'email',
),
array(
'name' => 'Address',
'desc' => 'Address',
'id' => 'Address',
'type' => 'text',
'visible' => [
'when' => [
['name', '!=', ''],
['email', '!=', '']
],
'relation' => 'or'
]
)
)
);
return $meta_boxes;
} );