Skip to content

Commit

Permalink
Improved "required" field detection. Closes #3305.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Oct 26, 2012
1 parent 559130b commit 0ddd130
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
19 changes: 19 additions & 0 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ class Contact extends CakeTestModel {
'between' => array('rule' => array('between', 5, 30), 'allowEmpty' => true),
),
'imnotrequiredeither' => array('required' => true, 'rule' => array('between', 5, 30), 'allowEmpty' => true),
'iamrequiredalways' => array(
'email' => array('rule' => 'email'),
'rule_on_create' => array('rule' => array('maxLength', 50), 'on' => 'create'),
'rule_on_update' => array('rule' => array('between', 1, 50), 'on' => 'update'),
),
);

/**
Expand Down Expand Up @@ -7068,6 +7073,20 @@ public function testFormInputRequiredDetection() {
'/div'
);
$this->assertTags($result, $expected);

$result = $this->Form->input('Contact.iamrequiredalways');
$expected = array(
'div' => array('class' => 'input text required'),
'label' => array('for' => 'ContactIamrequiredalways'),
'Iamrequiredalways',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][iamrequiredalways]',
'id' => 'ContactIamrequiredalways'
),
'/div'
);
$this->assertTags($result, $expected);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ protected function _isRequiredField($validationRules) {
}
foreach ($validationRules as $rule) {
$rule->isUpdate($this->requestType === 'put');
if ($rule->isEmptyAllowed()) {
return false;
if (!$rule->isEmptyAllowed()) {
return true;
}
}
return true;
return false;
}

/**
Expand Down

0 comments on commit 0ddd130

Please sign in to comment.