I noticed that I can't have a field with the same name in two or more different forms. Otherwise rules get merged, that is both fields need to comply with the rules from field A as well as from field B.

A solution might be to simply use two different names which is okay for custom forms, but not if you want to alter existing ones. In my case I have a comment reply form ("comment_form") under each comment on my page which the user can show if he/she clicks on the reply button. The comment_body field of the form for new comments has a rule set which those fields in the reply forms should not have. But they have due to this bug (or feature?).

In clientside_validation.module, rules are keyed by their field name in $js_rules[$name] everywhere which explains this behavior. On the other hand in JavaScript, Drupal.settings.clientsideValidation.forms contains an object with rule configuration for each form. In my case that means for "comment-form", "comment-form--2", "comment-form--3" and so on, but each of these are equal although they shouldn't.

Comments

do you have a demo, or can you provide me some code so we can test this?

Yes. Put this hook_form_FORM_ID_alter() into one of your modules, duplicating the search form's text field:

function my_module_form_comment_form_alter(&$form, &$form_state, $form_id) {
  // Create a second search field.
  $form['search_block_form'] = array(
    '#type' => 'textfield',
    '#title' => 'Another search_block_form field',
    '#rules' => array('numeric'),
  );
}

If you then clear your cache and open a page with both Drupal's search form and a comment form (e.g. a node page), you then have a search field in both forms. Enter e.g. "a" into both fields and click beside them. Both fields will throw the error "Use only numbers at Another search_block_form field." or something similar.

I just noticed that in Drupal.settings.clientsideValidation.forms in the inline JavaScript, every form has all the rules from all fields of the previous forms.

Status:Active» Needs review
StatusFileSize
new1.04 KB

It seems a possible solution is to have the clientside_validation_webform_after_build() and clientside_validation_form_after_build() use a non-static $js_rules variable.
All rules get merged in $js_rules for each form built during the request. clientside_validation_add_js_settings() then sends the duplicate rules to the JavaScript front-end side. All forms will have the rules for all form elements on the page. Some will get overridden if the have the same name - rules added later in the request will override existing ones essentially deleting them. This is the issue in a nutshell.

Status:Needs review» Fixed

Tested with code from #2 and confirmed the patch worked. Fixed in the latest dev version. Thanks for the patch!

Status:Fixed» Closed (fixed)

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