Support Forum
The following works:
add_filter( 'rwmb_normalize_designation_field', function( $field ) {
$field['attributes'] = ['minlength' => 20];
return $field;
});
But this does not:
add_filter( 'rwmb_normalize_designation_field', function( $field ) {
$field['validation'] = ['minlength' => 20];
return $field;
});
How can I make jquery validation work with rwmb_normalize_field?
Hi,
jQuery validation is used under meta box settings, please read more here
https://docs.metabox.io/validation/#using-code-1
then you can use the meta box normalize filter to modify meta box settings https://docs.metabox.io/filters/#rwmb_normalize_meta_box
If you want to use the HTML5 attribute for the field, just use the key minlength
add_filter( 'rwmb_normalize_designation_field', function( $field ) {
$field['minlength'] = 20;
return $field;
});
In your Field Settings page under Customize Field Settings it is mentioned that "This filter exposes the $field settings array for each field and allows customization to all settings."
Anyways, what I am trying to achieve cannot be done through HTML5 attribute for sure. Here's the case, kindly help me if you can:
I have used the Meta Box Builder to add a jQuery validation to my username field. It uses the remote parameter to ajax call a function and check if the username already exists before submitting the form. Now this works fine when I am creating a new post.
But when I try to edit the same post, the existing username is displayed in the field, and the ajax calls returns an error saying the username already exists - because it does.
So what I need to do is somehow stop the jQuery validation from firing when I am on the edit post page. How can this be achieved? Please understand that I am not using code but Meta Box Builder to create the Meta Box.
Hi,
Please refer to this topic to know how to use remote validation with the Builder https://support.metabox.io/topic/remote-validation-example/
Then you can check if the username existed or not and echo the true/false value.