mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-28 04:32:57 +00:00
Merge pull request #920 from ADmad/master-required-field
Improved "required" field detection. Closes #3305.
This commit is contained in:
commit
20483a22ff
2 changed files with 22 additions and 3 deletions
lib/Cake
|
@ -119,6 +119,11 @@ class Contact extends CakeTestModel {
|
||||||
'between' => array('rule' => array('between', 5, 30), 'allowEmpty' => true),
|
'between' => array('rule' => array('between', 5, 30), 'allowEmpty' => true),
|
||||||
),
|
),
|
||||||
'imnotrequiredeither' => array('required' => true, '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'),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7068,6 +7073,20 @@ class FormHelperTest extends CakeTestCase {
|
||||||
'/div'
|
'/div'
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -249,11 +249,11 @@ class FormHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
foreach ($validationRules as $rule) {
|
foreach ($validationRules as $rule) {
|
||||||
$rule->isUpdate($this->requestType === 'put');
|
$rule->isUpdate($this->requestType === 'put');
|
||||||
if ($rule->isEmptyAllowed()) {
|
if (!$rule->isEmptyAllowed()) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue