Custom Fields
Re-Envisioned
Support General Validation does not work for fields in group

This topic contains 6 replies, has 3 voices, and was last updated by  Truong Giang 1 year, 8 months ago.

  • Creator
    Topic
  • #6598

    ludovic.meyer
    Participant

    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,

Viewing 6 replies - 1 through 6 (of 6 total)
  • Author
    Replies
  • #6599

    ludovic.meyer
    Participant

    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' ),
                ),
            ),
        ),
    ),
    
    #6629

    Truong Giang
    Participant

    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' ),
    				),
    			),
    		),
    
    #6664

    ttroels
    Participant

    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…

    #6672

    Truong Giang
    Participant

    Hi,

    Sorry because current version of Meta Box Group only supports HTML5 validation via attributes when clone. Please use it if possible.

    Thanks.

    #6678

    ttroels
    Participant

    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 😉

    #6686

    Truong Giang
    Participant

    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.

Viewing 6 replies - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.