Skip to content
Permalink
Browse files

Fixing "required" field detection again. Closes #3305

  • Loading branch information...
ADmad committed Oct 31, 2012
1 parent b9ee4fc commit 26d8351af4e2ad0096287313beec8cf96ee79829
Showing with 25 additions and 3 deletions.
  1. +18 −0 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. +7 −3 lib/Cake/View/Helper/FormHelper.php
@@ -115,6 +115,10 @@ class Contact extends CakeTestModel {
'required_one' => array('required' => array('rule' => array('notEmpty'))),
'imnotrequired' => array('required' => false, 'rule' => 'alphaNumeric', 'allowEmpty' => true),
'imalsonotrequired' => array(
'alpha' => array('rule' => 'alphaNumeric', 'allowEmpty' => true),
'between' => array('rule' => array('between', 5, 30)),
),
'imalsonotrequired2' => array(
'alpha' => array('rule' => 'alphaNumeric', 'allowEmpty' => true),
'between' => array('rule' => array('between', 5, 30), 'allowEmpty' => true),
),
@@ -7060,6 +7064,20 @@ public function testFormInputRequiredDetection() {
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.imalsonotrequired2');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ContactImalsonotrequired2'),
'Imalsonotrequired2',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][imalsonotrequired2]',
'id' => 'ContactImalsonotrequired2'
),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.imnotrequiredeither');
$expected = array(
'div' => array('class' => 'input text'),
@@ -247,11 +247,15 @@ protected function _isRequiredField($validationRules) {
if (empty($validationRules) || count($validationRules) === 0) {
return false;
}
$isUpdate = $this->requestType === 'put';
foreach ($validationRules as $rule) {
$rule->isUpdate($this->requestType === 'put');
if (!$rule->isEmptyAllowed()) {
return true;
$rule->isUpdate($isUpdate);
if ($rule->skip()) {
continue;
}
return !$rule->allowEmpty;
}
return false;
}

0 comments on commit 26d8351

Please sign in to comment.
You can’t perform that action at this time.