Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing "required" field detection again. Closes #3305

  • Loading branch information...
commit 26d8351af4e2ad0096287313beec8cf96ee79829 1 parent b9ee4fc
@ADmad ADmad authored
View
18 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
@@ -116,6 +116,10 @@ class Contact extends CakeTestModel {
'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),
),
'imnotrequiredeither' => array('required' => true, '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'),
View
10 lib/Cake/View/Helper/FormHelper.php
@@ -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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.