Support Forum
Hello,
When fields are in a group, the validation does not works.
For example, in the metabox below :
- the litte red star displays next "Légende et crédits de la vidéo" (that's ok)
- the post can be publish even when "vm_video_legend" is empty
- "vm_video_link" displays the english validation message "Please enter a valid URL." instead of mine "Ce champ doit être une url valide".
$meta_boxes[] = array( 'title' => __( 'La résidence', 'vm' ), 'post_types' => array( 'residence' ), 'context' => 'normal', 'priority' => 'high', 'id' => 'vm_residence', 'fields' => array( array( 'name' => __( 'Vidéo', 'vm' ), 'id' => 'vm_video_group', 'type' => 'group', 'fields' => array( array( 'name' => __( 'Lien de la vidéo (Youtube, Vimeo)', 'vm' ), 'id' => 'vm_video_link', 'type' => 'oembed', ), array( 'name' => __( 'Légende et crédits de la vidéo', 'vm' ), 'id' => 'vm_video_legend', 'type' => 'text', ), ), ), ), 'validation' => array( 'rules' => array( 'vm_video_group' => array( "vm_video_link" => array( 'url' => true, ), "vm_video_legend" => array( 'required' => true, ), ), ), 'messages' => array( 'vm_video_group' => array( "vm_video_link" => array( 'url' => __( 'Ce champ doit être une url valide', 'vm' ), ), "vm_video_legend" => array( 'required' => __( 'Ce champ est requis', 'vm' ), ), ), ), ), );
I also tried to define validation rules and messages like below with no success
<?php
'validation' => array(
'rules' => array(
'vm_video_group' => array(
"vm_video_link" => array(
'url' => true,
),
"vm_video_legend" => array(
'required' => true,
),
),
),
'messages' => array(
'vm_video_group' => array(
"vm_video_link" => array(
'url' => __( 'Ce champ doit être une url valide', 'vm' ),
),
"vm_video_legend" => array(
'required' => __( 'Ce champ est requis', 'vm' ),
),
),
),
),
?>
Can you fix this please ?
Regards,
The second portion of code didn't display well. Look here :
'validation' => array( 'rules' => array( 'vm_video_group' => array( "vm_video_link" => array( 'url' => true, ), "vm_video_legend" => array( 'required' => true, ), ), ), 'messages' => array( 'vm_video_group' => array( "vm_video_link" => array( 'url' => __( 'Ce champ doit être une url valide', 'vm' ), ), "vm_video_legend" => array( 'required' => __( 'Ce champ est requis', 'vm' ), ), ), ), ),
Hi,
jQueryValidation bases on input id to check. So please change the validation param like this:
'validation' => array(
'rules' => array(
"vm_video_group_vm_video_link" => array(
'url' => true,
),
"vm_video_group_vm_video_legend" => array(
'required' => true,
),
),
'messages' => array(
"vm_video_group_vm_video_link" => array(
'url' => __( 'Ce champ doit être une url valide', 'vm' ),
),
"vm_video_group_vm_video_legend" => array(
'required' => __( 'Ce champ est requis', 'vm' ),
),
),
),
Here I discovered that the validation does work in groups, but only the first group.
If I create a cloneable group, so the other groups and fields don't have any validation in them, because the fields now have different id's than defined in our validation rules...
Hi,
Sorry because current version of Meta Box Group only supports HTML5 validation via attributes when clone. Please use it if possible.
Thanks.
Yes, I use the basic HTML5 validation as well, but I would like to implement both HTML5 and JS validation. Seems it don't quite work in cloneable groups. It's just for informing you about the issue 😉
Hi,
Thank you for your report. We will consider this problem in the future. ID of field in clonable group is dynamic, so we can't use old mechanism. This is a hard part.
Thank you very much.
+1,
2019 and the problem persists.
Certainly the solution of manually specifying the ID of the HTML field is not serious.
It forces us to implement a logic that metabox has already implemented previously to generate the ID property.
Other frameworks like carbonfields can manage this task effectively.
I'm also having this problem. I would like to validate fields inside a group.
function register_application_meta_boxes( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = array (
'title' => esc_html__( 'Job Application Form', 'zri-domain' ),
'id' => 'job-application-form',
'post_types' => array(
0 => 'job-application',
),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array (
'id' => $prefix . 'first-name',
'type' => 'text',
'name' => esc_html__( 'First Name', 'zri-domain' ),
'admin_columns' => array(
'position' => 'replace title',
'title' => 'First Name',
),
),
array (
'id' => $prefix . 'experience',
'type' => 'group',
'name' => esc_html__( 'Employment History', 'zri-domain' ),
'fields' => array(
array (
'id' => $prefix . 'start-date',
'type' => 'date',
'name' => esc_html__( 'Start Date', 'zri-domain' ),
'js_options' => array(
'dateFormat' => 'mm/dd/yy',
),
),
array (
'id' => $prefix . 'end-date',
'type' => 'date',
'name' => esc_html__( 'End Date', 'zri-domain' ),
'js_options' => array(
'dateFormat' => 'mm/dd/yy',
),
)
),
'clone' => 1,
'default_state' => 'expanded',
'add_button' => esc_html__( '+ Add Employment', 'zri-domain' ),
'collapsible' => true,
'group_title' => 'Employment {#}',
)
),
'validation' => array(
'rules' => array(
'experience' => array(
'start-date' => array(
'required' => true,
'date' => true
),
'end-date' => array(
'required' => true,
'date' => true
)
)
),
)
);
return $meta_boxes;
}
Hi Jason,
We are working to cover this case, please use the HTML validation to validate sub-fields inside the cloneable group.
array (
'id' => $prefix . 'experience',
'type' => 'group',
'name' => esc_html__( 'Employment History', 'zri-domain' ),
'fields' => array(
array (
'id' => $prefix . 'start-date',
'type' => 'date',
'name' => esc_html__( 'Start Date', 'zri-domain' ),
'js_options' => array(
'dateFormat' => 'mm/dd/yy',
),
'required' => true //This
),
array (
'id' => $prefix . 'end-date',
'type' => 'date',
'name' => esc_html__( 'End Date', 'zri-domain' ),
'js_options' => array(
'dateFormat' => 'mm/dd/yy',
),
'required' => true //This
)
),
'clone' => 1,
'default_state' => 'expanded',
'add_button' => esc_html__( '+ Add Employment', 'zri-domain' ),
'collapsible' => true,
'group_title' => 'Employment {#}',
)
Any update on this? Field group validations would be a great addition.
Ditto. Any plans to fix it?
Still not fixed... wow!
You should update the validation doc about it... this aint working for any fields inside a group! Wasted my time again!