Hi guys,

I think I found potential bug on the module when you have a form with required checkboxed that it is rendered twice in the page. They do not validate properly.

The form is rendered twice because of the node_view but that is different topic.

I investigate down the track, there is misconfigured settings under Drupal.settings.clientsideValidation.forms.[form-name].checkboxrules.[component-name].checkboxgroupminmax

The array grows depends on how many forms attached. If you have two forms, the array size is 6, if three forms attached become 9.. Which it should have 3 items inside.

Here is how to replicate

<?php
function mymodule_form1()
  {
   
$form = array();
   
$form["myoption"] = array(
     
"#type" => "checkboxes",
     
'#options' => array("1", "2", "3"),
     
'#required' => TRUE,
    );
   
$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
    return
$form;
  }
?>

Render the form,

<?php
function mymodule_testform()
{
   return
drupal_render(drupal_get_form('mymodule_form1')) . drupal_render(drupal_get_form('mymodule_form1'));
}
?>

This is the Drupal.settings
{"forms":{"mymodule-form1":{"errorPlacement":1, "general":{"errorClass":"error", "wrapper":"li", "validateTabs":"", "scrollTo":1, "scrollSpeed":1000, "disableHtml5Validation":1, "validateOnBlur":1, "validateOnBlurAlways":0, "validateOnKeyUp":1, "validateOnSubmit":1, "showMessages":0, "errorElement":"label"}, "checkboxrules":{"myoption":{"checkboxgroupminmax":[ 1, 3, "#edit-myoption", 1, 3, "#edit-myoption--2" ], "messages":{"checkboxgroupminmax":"You must select between 1 and 3 values for myoption."}}}, "rules":{"myoption":{"messages":{"required":"myoption field is required."}, "required":true}}}, "mymodule-form1--2":{"errorPlacement":1, "general":{"errorClass":"error", "wrapper":"li", "validateTabs":"", "scrollTo":1, "scrollSpeed":1000, "disableHtml5Validation":1, "validateOnBlur":1, "validateOnBlurAlways":0, "validateOnKeyUp":1, "validateOnSubmit":1, "showMessages":0, "errorElement":"label"}, "checkboxrules":{"myoption":{"checkboxgroupminmax":[ 1, 3, "#edit-myoption", 1, 3, "#edit-myoption--2" ], "messages":{"checkboxgroupminmax":"You must select between 1 and 3 values for myoption."}}}, "rules":{"myoption":{"messages":{"required":"myoption field is required."}, "required":true}}}}, "general":{"usexregxp":0}, "groups":{"mymodule-form1":{}, "mymodule-form1--2":{}}}

Please check the checkboxgroupminmax, it is 6 items, which it should be only last 3 in the Array

I am going to send my patch to fix this issue, but I would like to hear from the code maintainers on your thoughts.

Thanks

Comments

The fixes is actually find all the code to replace the code of changing post ID
#edit-myoption--2 to #edit-myoption

Search all:
/.*?(--(\d)*)/

And you will find 4 occurrences inside the module folder. Commented out the the form ID replacement.

<?php
//$form_id = str_replace($matches[1], '', $form_id);
?>

Reload the page and it works. Maintainers, what are those code for? What is the purpose of the replacing the form ID?

Thanks

We added these lines in #1651760: Multiple value fields not validating correctly. I'll try to find out if we can do it differently

Status:Active» Fixed

Since there's no way of telling whether the entire form is being replaced by ajax or if it's rendered twice on a page (and thus will have an other html id) or only one field in the form is added/changed (as is the case with a multiple value field). Our only choice really is to add the settings twice.

Fixed in latest dev version. I tested with a multiple value field and with a form rendered twice on a page.

Thanks for the report and debugging!

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Adding other form of different types via the ajax update fails

Issue summary:View changes
Status:Closed (fixed)» Active

Version:7.x-1.37» 7.x-1.38

@lorisb can you be more specific? Maybe provide us with some example code?

I have a page with a editablefield field. When I load a form through node_add () with ajax, the update function of clientside_validation's module is not executed.
I also tried to disable the editablefield field but still error.

Status:Active» Fixed

7.x-1.39 version solves the problem.

Status:Fixed» Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.