Support Forum
Support › Meta Box Group › Validation Bug with Cloned Items - Metabox Group + Frontend Form
Hi there,
I have discovered a minor bug in the MB Group Extension when using validation on cloned groups within an MB frontend submission form.
ENV
=============
WP: 6.4.3
MB: 5.9.4
MB AIO: 1.24.3
PHP: 8.2
Node JS: 18.13.0
Browser: Chrome 122.0.6261.112
STEPS TO RECREATE
======================
* Note that I do not use the 'Metabox Builder' to create my custom fields.
1) Create a custom post type.
2) Add cloneable MB group of custom fields that is associated with the custom post type.
3) Add validation to one or more of the cloneable custom field groups.
4) Add the custom fields to a MB Frontend submission form.
5) Create a Completely NEW (unsaved) frontend post as a registered user.
6) Enter data into the fields in the FIRST cloneable group but MAKE SURE you FAIL the validation on one or more of the fields so that you see an error message displayed below the failing field. Then correct the error.
7) Use the "Add New" (clone) button to add a new field group and FAIL the validation on one or more fields in the NEWLY cloned group.
OUTCOME
====================
You will see that in "Step 7" the individual field validation error message does NOT show below the fields in the NEWLY CLONED group but below the corresponding field in the FIRST GROUP?
I only stumbled upon this issue by chance during some testing.
EG Custom Field Setup:
////////////////////////////////////
// Submit Post - Custom Fields
////////////////////////////////////
add_filter( 'rwmb_meta_boxes', 'pl_submit_custom_post' );
function pl_submit_custom_post( $meta_boxes ) {
$prefix = 'abc_';
$meta_boxes[] = [
'validation' => [
// RULES
'rules' => [
'post_title' => [
'maxlength' => '50',
],
'group_field_one' => [
'maxlength' => '50',
],
'group_field_two' => [
'maxlength' => '20',
'pattern' => '^[a-zA-Z0-9\s_-]+$',
],
],
// MESSAGES
'messages' => [
'post_title' => [
'maxlength' => 'Shorten your post title! No more than 50 characters including spaces.',
],
'group_field_one' => [
'maxlength' => 'No more than 50 characters including spaces.',
],
'group_field_two' => [
'maxlength' => 'No more than 20 characters including spaces.',
'pattern' => 'Use only letters, numbers, underscores or hyphens please.',
],
],
],
'title' => __( 'Submit Custom Post', 'text-domain' ),
'id' => 'submit-custom_post',
'post_types' => ['user_custom_post'],
'revision' => true,
'fields' => [
[
'name' => __( 'Custom Post title', 'text-domain' ),
'id' => 'post_title',
'type' => 'text',
'desc' => __( 'Use strong, vivid language that describes exactly what you are about to launch (Max 50 characters).', 'text-domain' ),
'required' => true,
],
[
'name' => __( 'Group Fields', 'text-domain' ),
'id' => 'group_fields',
'add_button' => __( 'Add New', 'text-domain' ),
'type' => 'group',
'clone' => true,
'sort_clone' => true,
'group_title' => 'Group Title {#}',
'collapsible' => true,
'save_state' => true,
'max_clone' => 3,
// List of sub-fields.
'fields' => [
[
'name' => __( 'Group Field One', 'text-domain' ),
'desc' => __( 'A unique name for this field (Max 50 characters).', 'text-domain' ),
'id' => 'group_field_one',
'type' => 'text',
],
[
'name' => __( 'Group Field Two', 'text-domain' ),
'desc' => __( 'A unique code for this field. (Max 20 characters)', 'text-domain' ),
'id' => 'group_field_two',
'type' => 'text',
],
],
],
],
];
return $meta_boxes;
}
I can also confirm that I see NO errors in the browser console or my PHP debug.log relating to my build.
I look forward to your response.
Thanks in advance 🙂
Hello,
I can reproduce the issue on my demo site. I've escalated this issue to the development team to fix it in future updates.
Thank you.
Hi Peter,
thanks for escalating.
I look forward to the fix!