Permalink
Browse files

Fix required field detection.

Fix required field detection to match documentation and behavior when
validating. Having `allowEmpty` in the first validation rule, makes the
field not 'required' as the field is allowed to be empty.

Fixes #3194
  • Loading branch information...
markstory committed Sep 12, 2012
1 parent 2bbf6bd commit 99a9cc96693a62a8f64510fd7d312f760a40540b
Showing with 7 additions and 5 deletions.
  1. +1 −2 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. +6 −3 lib/Cake/View/Helper/FormHelper.php
@@ -107,8 +107,7 @@ class Contact extends CakeTestModel {
'imrequiredonupdate' => array('notEmpty' => array('rule' => 'alphaNumeric', 'on' => 'update')),
'imrequiredoncreate' => array('required' => array('rule' => 'alphaNumeric', 'on' => 'create')),
'imrequiredonboth' => array(
'required' => array('rule' => 'alphaNumeric', 'allowEmpty' => true),
'check' => array('rule' => 'alphaNumeric')
'required' => array('rule' => 'alphaNumeric'),
),
'string_required' => 'notEmpty',
'imalsorequired' => array('rule' => 'alphaNumeric', 'allowEmpty' => false),
@@ -244,13 +244,16 @@ protected function _introspectModel($model, $key, $field = null) {
* @return boolean true if field is required to be filled, false otherwise
*/
protected function _isRequiredField($validationRules) {
if (empty($validationRules) || count($validationRules) === 0) {
return false;
}
foreach ($validationRules as $rule) {
$rule->isUpdate($this->requestType === 'put');
if (!$rule->isEmptyAllowed()) {
return true;
if ($rule->isEmptyAllowed()) {
return false;
}
}
return false;
return true;
}
/**

0 comments on commit 99a9cc9

Please sign in to comment.