mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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
This commit is contained in:
parent
2bbf6bd568
commit
99a9cc9669
2 changed files with 7 additions and 5 deletions
|
@ -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 @@ class FormHelper extends AppHelper {
|
|||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue