Navigation Menu

Skip to content

Commit

Permalink
Fixing "required" field detection again. Closes #3305
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Oct 31, 2012
1 parent b9ee4fc commit 26d8351
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
18 changes: 18 additions & 0 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -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),
),
Expand Down Expand Up @@ -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'),
Expand Down
10 changes: 7 additions & 3 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -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;
}
Expand Down

0 comments on commit 26d8351

Please sign in to comment.