It would be really neat if a rule could specify a callback for generating the error message.

The current selection of just replacing the field name tends to be a anemic for creating a nice user experience, especially when you have more complicated calculations you do to validate a field and would like to give useful explanations why the value was rejected.

Comments

pedrofaria’s picture

Assigned: Unassigned » pedrofaria

will be available on next release.. more information for usage will be added at project page.

Thank you!

pedrofaria’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

bropp’s picture

Version: 7.x-1.1 » 7.x-2.x-dev
Status: Closed (fixed) » Needs review
StatusFileSize
new821 bytes

I found myself needing a slightly different functionality. A patch is attached that allows a module's hook_fapi_validation_rules() implementation to define custom 'error callback' functions for each validator, instead of having to specify one in the form #rules definition. If error message or error callback has been defined in #rules form array, the default callback will not be used.

An example:

/**
 * Implements hook_fapi_validation_rules().
 */
function my_module_fapi_validation_rules() {
  return array(
    'my_validator' => array(
      'callback' => 'my_validator_callback',
      'error callback' => 'my_validator_error_callback', // will only run if an error message or callback is not defined in the form.
    ),
  );
}

bropp’s picture

Fixed formatting error in comment.

jnicola’s picture

Issue summary: View changes
Status: Needs review » Fixed

While potentially useful, this seems to give up very useful and common basic functionality in favor of your desire for custom functionality.

If you can come back with a concept and patch that can accomplish both, that would be sensible. If I missed something reopen it as well, and please help me see what I missed.

Thanks!

Marking fixed as the initial request works

Status: Fixed » Closed (fixed)

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