Hi.
i provided custom webform validation for custom webform field
so. i created component by means of _webform_defaults_component
My components was multiply and it has form name like like submitted[my_componet][id_of_component]
it works fanny for webform, but it has some problems with webform_validation module

hook webform_validation_validate should return a errors array with keys a contained name of field

$errors['item_1'] = 'erros text';

i propose to allowed using multi keys

$errors['item_1'][id_of_value] = 'erros text';

so, i'm attached patch to decide this problem

p.s. I can provide more information to answer why this problem is important

Comments

liam morland’s picture

Priority: Major » Normal

Can you explain more why this is needed? Are you making a custom component which is a compound component, that is, one component which contains multiple form controls or multiple parts?

spheresh’s picture

StatusFileSize
new5.27 KB

My custom component is a table, one of cell is input field. It has nothing to do with the compound component of multiple form (multi step form), just simple component, but this component can have to much values.

after form was submitted, drupal showing a error
Error example

but, it is wrong. field that contains the values ​​for the item2 should not be highlighted as an error

so this patch allows to highlight a field that is a name like this
submitted[orders][MULTI_FIELD_ID]

P.S. "webform_submitted_data" database table has field "no" for save multi values, but anyother component did not use it for highlighted element of form, now.

spheresh’s picture

Status: Active » Needs review
liam morland’s picture

Status: Needs review » Needs work

The patch does not apply. Please re-roll against the latest development version.

spheresh’s picture

Status: Needs work » Needs review
StatusFileSize
new1.72 KB
liam morland’s picture

Do I have this right: You have a custom Webform component which has multiple HTML form controls in it. With this patch, you can set errors against the individual sub-components instead of only against the entire component. Is that right?

spheresh’s picture

You are right. I'm using it in my some projects. I'm contributing one of this (link for example Webform Orders)

You may think that it is my local problem, but it is not right.
Webform using a multiple values. For example, a data field using multi value also.

Only local images are allowed.

we can see on this is screen what a day field is filled correctly, but it is marked as wrong, so only month and year fields should be to marked

this patch allow make a validation a more clearly, like screen
example 2

Example of validator


/**
 * Implements hook_webform_validation_validate().
 */
function webform_validation_webform_validation_validate($validator_name, $items, $components, $rule) {

....

      case 'date_requared':
        foreach ($items as $key => $item) {
          foreach ($item as $type => $value) {
            if(!is_numeric($value) || empty($value)){
              $error = t('%item can be nummeric', array('%item' => $type));
              $errors[$key][$type] = $error;
            }
          }
        }

        return $errors;

  ....

}

P.S. I wrote this validator is very fast, only to show the principle of the patch)

liam morland’s picture

liam morland’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Fixed » Patch (to be ported)
liam morland’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Issue summary: View changes
Status: Patch (to be ported) » Closed (fixed)

Drupal 6 is no longer supported.