Skip to content

Commit

Permalink
Issue #799356 by vijaycs85, m1n0, jaffaralia, effulgentsia: Fixed _fo…
Browse files Browse the repository at this point in the history
…rm_set_class() is too aggressive in assigning the 'error' class.
  • Loading branch information
DavidRothstein committed Apr 1, 2013
1 parent 005708c commit 154389d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion includes/form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4167,7 +4167,7 @@ function _form_set_class(&$element, $class = array()) {
if (!empty($element['#required'])) {
$element['#attributes']['class'][] = 'required';
}
if (isset($element['#parents']) && form_get_error($element) !== NULL) {
if (isset($element['#parents']) && form_get_error($element) !== NULL && !empty($element['#validated'])) {
$element['#attributes']['class'][] = 'error';
}
}
Expand Down
11 changes: 11 additions & 0 deletions modules/simpletest/tests/form.test
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,17 @@ class FormValidationTestCase extends DrupalWebTestCase {
$this->assertText(t('!name field is required.', array('!name' => 'Title')));
$this->assertText('Test element is invalid');
}

/**
* Tests error border of multiple fields with same name in a page.
*/
function testMultiFormSameNameErrorClass() {
$this->drupalGet('form-test/double-form');
$edit = array();
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertFieldByXpath('//input[@id="edit-name" and contains(@class, "error")]', NULL, 'Error input form element class found for first element.');
$this->assertNoFieldByXpath('//input[@id="edit-name--2" and contains(@class, "error")]', NULL, 'No error input form element class found for second element.');
}
}

/**
Expand Down

0 comments on commit 154389d

Please sign in to comment.