If a required form-element (textfield) is submitted empty, error message is displayed, but the class "error" is not added to the input as it is with required form-item.
screenshot

CommentFileSizeAuthor
#2 error.jpg64.3 KBAnonymous (not verified)
validation.jpg75.61 KBwildfeed

Comments

wildfeed’s picture

Issue summary: View changes

added screenshot

franz’s picture

Status: Active » Postponed (maintainer needs more info)

I take it is not a usual textfield, is it? How can we reproduce?

Anonymous’s picture

StatusFileSize
new64.3 KB

I'm having a similar problem on a field with custom validation. I'm building a multi-step form with these interdependent elements:

  $hasWebsite = array(
    0 => t(''),
	1 => t('No'),
    2 => t('Yes')
  );
  $form['website']['hasWebsite'] = array(
    '#type' => 'radios',
    '#title' => t('Do you have a website?'),
    '#options' => $hasWebsite,
    '#default_value' => isset($node->hasWebsite) ? $node->hasWebsite : '0',
    '#required' => TRUE,
  ); 
  $form['website']['url'] = array(
    '#type' => 'textfield',
    '#title' => t('Site URL (e.g., &104;ttp://sitename.com or &104;ttps://mysite.net/sitename)'),
    '#default_value' => 'http://TypeYourSiteAddressHere.com',
    '#states' => array(
      'required' => array(
       ':input[name="website[hasWebsite]"]' => array('value' => '2')
      ),
      'visible' => array(
       ':input[name="website[hasWebsite]"]' => array('value' => '2')
      )
    ),
  );

… and this custom validation:

function my_custom_module_website_info_validate($form, &$form_state) {
  if ($form_state['values']['website']['hasWebsite'] == '0') {
    form_set_error('submitted][hasWebsite', t('You didn’t tell us whether you have a website.'));
  }
  if ($form_state['values']['website']['hasWebsite'] == '2') {
    if ($form_state['values']['website']['url'] == 'http://TypeYourSiteAddressHere.com' || $form_state['values']['website']['url'] == '') {
      form_set_error('submitted][url', t('You said you have a website, but you didn’t tell us the address'));
    }
  }
}

If I select 'Yes' (value = '2') and submit without altering the default text in the next field, I get the custom error message ('You said you have a website, but you didn’t tell us the address'), but the error class is not added to the element. Same thing with an empty textfield; error message displayed, as expected, but no error class added to field.

Note: I had to encode the 'h' in http ('&104;ttp') for the title strings to post my code here without links being inserted by the comment system.

franz’s picture

'submitted][url' is not the right argument here, 'url' is. Please read the docs on form_set_error()

Anyways, not sure if it's the same issue as original.

dddave’s picture

Category: bug » support
Status: Postponed (maintainer needs more info) » Closed (fixed)

Closing old, stale issues. Re-open if your problem persists.

dddave’s picture

Issue summary: View changes

edited