Skip to content

Commit

Permalink
Making the form helper put the "required" class on all imputs that ha…
Browse files Browse the repository at this point in the history
…ve a validation rule and does not explicitly sets allowEmpty => true in validation array
  • Loading branch information
lorenzo committed Feb 28, 2010
1 parent 056b87d commit 0ca5c11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions cake/libs/view/helpers/form.php
Expand Up @@ -152,14 +152,11 @@ function _isRequiredField($validateProperties) {
}

foreach ($validateProperties as $rule => $validateProp) {
$rule = isset($validateProp['rule']) ? $validateProp['rule'] : false;
if ($rule) {
$rule = is_array($rule) ? array_shift($rule) : $rule;
$rule = is_string($rule) ? strtolower($rule) : $rule;
if (isset($validateProp['allowEmpty']) && $validateProp['allowEmpty'] === true) {
return false;
}
$required = empty($validateProp);
$required = $required || (!empty($rule) && $rule === 'notempty');
$required = $required || (isset($validateProp['allowEmpty']) && $validateProp['allowEmpty'] !== true);
$rule = isset($validateProp['rule']) ? $validateProp['rule'] : false;
$required = $rule || empty($validateProp);
if ($required) {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -108,7 +108,7 @@ class Contact extends CakeTestModel {
'imalsorequired' => array('rule' => 'alphaNumeric', 'allowEmpty' => false),
'imrequiredtoo' => array('rule' => 'notEmpty'),
'required_one' => array('required' => array('rule' => array('notEmpty'))),
'imnotrequired' => array('required' => false, 'rule' => 'alphaNumeric'),
'imnotrequired' => array('required' => false, 'rule' => 'alphaNumeric', 'allowEmpty' => true),
'imalsonotrequired' => array('alpha' => array('rule' => 'alphaNumeric','allowEmpty' => true),
'between' => array('rule' => array('between', 5, 30))));

Expand Down

0 comments on commit 0ca5c11

Please sign in to comment.