Issue #1785436 by Boobaa: Fixed Submission of #required elements without #title and empty value does not display any error.
parent
6da30cc2e5
commit
f5955bfead
|
@ -4590,7 +4590,7 @@ function _form_set_class(&$element, $class = array()) {
|
||||||
$element['#attributes']['required'] = 'required';
|
$element['#attributes']['required'] = 'required';
|
||||||
$element['#attributes']['aria-required'] = 'true';
|
$element['#attributes']['aria-required'] = 'true';
|
||||||
}
|
}
|
||||||
if (isset($element['#parents']) && form_get_error($element)) {
|
if (isset($element['#parents']) && form_get_error($element) !== NULL) {
|
||||||
$element['#attributes']['class'][] = 'error';
|
$element['#attributes']['class'][] = 'error';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,6 +219,38 @@ class FormTest extends WebTestBase {
|
||||||
$this->assertRaw("The form_test_validate_required_form form was submitted successfully.", 'Validation form submitted successfully.');
|
$this->assertRaw("The form_test_validate_required_form form was submitted successfully.", 'Validation form submitted successfully.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests validation for required textfield element without title.
|
||||||
|
*
|
||||||
|
* Submits a test form containing a textfield form element without title.
|
||||||
|
* The form is submitted twice, first without value for the required field
|
||||||
|
* and then with value. Each submission is checked for relevant error
|
||||||
|
* messages.
|
||||||
|
*
|
||||||
|
* @see form_test_validate_required_form_no_title()
|
||||||
|
*/
|
||||||
|
function testRequiredTextfieldNoTitle() {
|
||||||
|
$form = $form_state = array();
|
||||||
|
$form = form_test_validate_required_form_no_title($form, $form_state);
|
||||||
|
|
||||||
|
// Attempt to submit the form with no required field set.
|
||||||
|
$edit = array();
|
||||||
|
$this->drupalPost('form-test/validate-required-no-title', $edit, 'Submit');
|
||||||
|
$this->assertNoRaw("The form_test_validate_required_form_no_title form was submitted successfully.", 'Validation form submitted successfully.');
|
||||||
|
|
||||||
|
// Check the page for the error class on the textfield.
|
||||||
|
$this->assertFieldByXPath('//input[contains(@class, "error")]', FALSE, 'Error input form element class found.');
|
||||||
|
|
||||||
|
// Submit again with required fields set and verify that there are no
|
||||||
|
// error messages.
|
||||||
|
$edit = array(
|
||||||
|
'textfield' => $this->randomString(),
|
||||||
|
);
|
||||||
|
$this->drupalPost(NULL, $edit, 'Submit');
|
||||||
|
$this->assertNoFieldByXpath('//input[contains(@class, "error")]', FALSE, 'No error input form element class found.');
|
||||||
|
$this->assertRaw("The form_test_validate_required_form_no_title form was submitted successfully.", 'Validation form submitted successfully.');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test default value handling for checkboxes.
|
* Test default value handling for checkboxes.
|
||||||
*
|
*
|
||||||
|
|
|
@ -30,6 +30,13 @@ function form_test_menu() {
|
||||||
'access callback' => TRUE,
|
'access callback' => TRUE,
|
||||||
'type' => MENU_CALLBACK,
|
'type' => MENU_CALLBACK,
|
||||||
);
|
);
|
||||||
|
$items['form-test/validate-required-no-title'] = array(
|
||||||
|
'title' => 'Form #required validation without #title',
|
||||||
|
'page callback' => 'drupal_get_form',
|
||||||
|
'page arguments' => array('form_test_validate_required_form_no_title'),
|
||||||
|
'access callback' => TRUE,
|
||||||
|
'type' => MENU_CALLBACK,
|
||||||
|
);
|
||||||
$items['form-test/limit-validation-errors'] = array(
|
$items['form-test/limit-validation-errors'] = array(
|
||||||
'title' => 'Form validation with some error suppression',
|
'title' => 'Form validation with some error suppression',
|
||||||
'page callback' => 'drupal_get_form',
|
'page callback' => 'drupal_get_form',
|
||||||
|
@ -488,6 +495,26 @@ function form_test_validate_required_form_submit($form, &$form_state) {
|
||||||
drupal_set_message('The form_test_validate_required_form form was submitted successfully.');
|
drupal_set_message('The form_test_validate_required_form form was submitted successfully.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form constructor to test the #required property without #title.
|
||||||
|
*/
|
||||||
|
function form_test_validate_required_form_no_title($form, &$form_state) {
|
||||||
|
$form['textfield'] = array(
|
||||||
|
'#type' => 'textfield',
|
||||||
|
'#required' => TRUE,
|
||||||
|
);
|
||||||
|
$form['actions'] = array('#type' => 'actions');
|
||||||
|
$form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Submit');
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form submission handler for form_test_validate_required_form_no_title().
|
||||||
|
*/
|
||||||
|
function form_test_validate_required_form_no_title_submit($form, &$form_state) {
|
||||||
|
drupal_set_message('The form_test_validate_required_form_no_title form was submitted successfully.');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a simple form with a button triggering partial validation.
|
* Builds a simple form with a button triggering partial validation.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue