I have a module which extends views_handler_field_history_user_timestamp. It adds some additional form elements to the "Node: has new content" form. I also have a validation function which validates the data. If validation fails the form should throw an error and the appropriate form element highlighted.

Problem is that it doesn't work. The element in question is within a fieldset. According to the documentation, you should be able to highlight the form element within a fieldset using the following syntax:

form_set_error('fieldset_name][element_name', t('Error message'));

But for some reason it doesn't work. The error message will display, but the element in question is not highlighted.

Any suggestions on how to get this working?

Regards,

Begun

Source code (shortened for brevity):

class views_ephemeral_field_handler_field_history_user_timestamp extends views_handler_field_history_user_timestamp {
  function init(&$view, $options) {
    // Since we are completely overriding this function from that of its parent,
    // we must ensure that the parent of the parent function is called.
    views_handler_field_node::init($view, $options);

    $this->additional_fields['created'] = array('table' => 'node', 'field' => 'created');
    $this->additional_fields['changed'] = array('table' => 'node', 'field' => 'changed');
    if (module_exists('comment') && !empty($this->options['comments'])) {
      $this->additional_fields['last_comment'] = array('table' => 'node_comment_statistics', 'field' => 'last_comment_timestamp');
    }
    // Get the value of option 'ephemeral' for reference by other methods.
    $this->ephemeral['enabled'] = $this->options['ephemeral']['enabled'];
    $this->ephemeral['units'] = $this->options['ephemeral']['units'];
    $this->ephemeral['delay'] = $this->options['ephemeral']['delay'];
  }

  function option_definition() {
    $options = parent::option_definition();

    $options['ephemeral']['enabled'] = array('default' => FALSE);

    return $options;
  }

  function options_validate($form, $form_state) {
    $regex_pattern = '/^[0-9]{1,}$/';
    if ($form_state['input']['options']['ephemeral']['enabled'] == 1 && preg_match($regex_pattern, $form_state['input']['options']['ephemeral']['delay']) < 1) {
      form_set_error('ephemeral][delay', t('Duration of time must be an integer.'));
    }
  }

  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $form['ephemeral'] = array(
      '#type' => 'fieldset',
      '#title' => t('Ephemeral'),
      '#description' => t('Content shall be marked as \'New\' or \'Updated\' for anonymous users for a set time period after the content has been created or updated. This provides a method for showing new or updated markers to anonymous users.'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['ephemeral']['enabled'] = array(
      '#type' => 'checkbox',
      '#title' => t('Make markers viewable to anonymous users.'),
      '#default_value' => !empty($this->options['ephemeral']['enabled']),
    );
    $form['ephemeral']['units'] = array(
      '#type' => 'select',
      '#title' => t('Units'),
      '#description' => t('Select units of time.'),
      '#options' => array(
        'mins' => t('Mins'),
        'hours' => t('Hours'),
        'days' => t('Days'),
      ),
      '#default_value' => isset($this->options['ephemeral']['units']) ? $this->options['ephemeral']['units'] : 'hours',
    );
    $form['ephemeral']['delay'] = array(
      '#type' => 'textfield',
      '#title' => t('Duration'),
      '#size' => 3,
      '#description' => t('Enter how many of units of time the marker should be displayed for anonymous users after creating or updating content.'),
      '#default_value' => isset($this->options['ephemeral']['delay']) ? $this->options['ephemeral']['delay'] : 0,
    );

  }

}

Comments

dawehner’s picture

Try out this:

form_set_error('options][fieldset_name][element_name', t('Error message'));

This should work.

begun’s picture

That worked perfectly. Thank you.

dawehner’s picture

Status: Active » Fixed

Update status.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Oops, forgot to add source code