Making the form helper put the "required" class on all imputs that have a validation rule and does not explicitly sets allowEmpty => true in validation array

This commit is contained in:
José Lorenzo Rodríguez 2010-02-27 22:58:27 -04:30
parent 056b87d13a
commit 0ca5c11e6c
2 changed files with 5 additions and 8 deletions

View file

@ -152,14 +152,11 @@ class FormHelper extends AppHelper {
}
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;
}

View file

@ -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))));