Validation does not work for fields in group
- This topic has 13 replies, 9 voices, and was last updated 1 year, 11 months ago by
ALEXANDRE GRAVEL-MÉNARD.
-
AuthorPosts
-
August 11, 2017 at 6:59 PM #6598
ludovic.meyer
ParticipantHello,
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,
August 11, 2017 at 7:06 PM #6599ludovic.meyer
ParticipantThe 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' ), ), ), ), ),
August 14, 2017 at 2:52 PM #6629Truong Giang
ParticipantHi,
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' ), ), ), ),
August 17, 2017 at 4:24 AM #6664ttroels
ParticipantHere 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...August 17, 2017 at 10:00 AM #6672Truong Giang
ParticipantHi,
Sorry because current version of MB Group only supports HTML5 validation via attributes when clone. Please use it if possible.
Thanks.
August 17, 2017 at 7:36 PM #6678ttroels
ParticipantYes, 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 😉
August 18, 2017 at 8:29 AM #6686Truong Giang
ParticipantHi,
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.
November 25, 2019 at 8:22 PM #17122GrupoADSLZone
Participant+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.
October 6, 2020 at 11:05 PM #22307Jason
ParticipantI'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; }
October 7, 2020 at 10:10 AM #22308Long Nguyen
ModeratorHi 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 {#}', )
October 13, 2021 at 10:04 PM #31300Austin Passy
ParticipantAny update on this? Field group validations would be a great addition.
October 27, 2022 at 1:21 AM #38839Piotr
ParticipantDitto. Any plans to fix it?
April 26, 2023 at 7:24 AM #41612ALEXANDRE GRAVEL-MÉNARD
ParticipantStill not fixed... wow!
April 26, 2023 at 7:25 AM #41613ALEXANDRE GRAVEL-MÉNARD
ParticipantYou should update the validation doc about it... this aint working for any fields inside a group! Wasted my time again!
-
AuthorPosts
- You must be logged in to reply to this topic.