Permalink
Browse files

Making the form helper put the "required" class on all imputs that ha…

…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 0ca5c11e6ca2dd356ca9416f570ba38ae27ee337
Showing with 5 additions and 8 deletions.
  1. +4 −7 cake/libs/view/helpers/form.php
  2. +1 −1 cake/tests/cases/libs/view/helpers/form.test.php
@@ -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;
}
@@ -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))));

0 comments on commit 0ca5c11

Please sign in to comment.