Error from hook_field_validate() isn't detected by hook_field_widget_error()

Just like the title says, for some reason my hook_field_widget_error() isn't getting fired.

Here's my code:

hook_field_validate():

function guideform_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, $errors) {   foreach ($items as $delta => $item) {     foreach (array('fullItems', 'startItems') as $column) {       if (!empty($item[$column])) {         $fieldName = $instance['field_name'];         switch ($column) {           case 'fullItems':             if (drupal_strlen($item[$column]) > 200) {               $message = t("The field {$fieldID} is too big");             }             break;           case 'startItems':             if (drupal_strlen($item[$column]) > 100) {               $message = t("The field {$fieldID} is too big");             }             break;         }         if (isset($message)) {                     $errors[$field['field_name']][$langcode][$delta][] = array(              'error' => "field_max_length",             'message' => $message,           );           //dpm just for checking, prints correctly           dpm($errors); //appears with the same format of other implementations of this hook         }       }     }   } } 

hook_field_widget_error():

function guideform_field_widget_error($element, $error, $form, &$form_state) {    dpm($error); //this doesn't print, hook is not fired   switch ($error['error']) {     case 'field_max_length':       form_error($element, $error['message']);       break;   } } 

Just for comparison, these are the same hooks implemented in the examples module by the field example:

hook_field_validate():

function field_example_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {   foreach ($items as $delta => $item) {     if (!empty($item['rgb'])) {       if (!preg_match('@^#[0-9a-f]{6}[email protected]', $item['rgb'])) {         $errors[$field['field_name']][$langcode][$delta][] = array(           'error' => 'field_example_invalid',           'message' => t('Color must be in the HTML format #abcdef.'),         );       }     }   } } 

hook_field_widget_error():

function field_example_field_widget_error($element, $error, $form, &$form_state) {   switch ($error['error']) {     case 'field_example_invalid':       form_error($element, $error['message']);       break;   } } 

These do work as intended. Is there anything else I should look for aside from those 2 hooks in order to be able to flag those field errors?

Replay

Category: 7 Time: 2016-07-31 Views: 4
Tags: forms fields

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.229 (s). 12 q(s)