Improved "required" field detection. Closes #3305.

This commit is contained in:
ADmad 2012-10-26 12:58:24 +05:30
parent 559130b87b
commit 0ddd130833
2 changed files with 22 additions and 3 deletions

View file

@ -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'),
),
);
/**
@ -7068,6 +7073,20 @@ class FormHelperTest extends CakeTestCase {
'/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);
}
/**

View file

@ -249,12 +249,12 @@ class FormHelper extends AppHelper {
}
foreach ($validationRules as $rule) {
$rule->isUpdate($this->requestType === 'put');
if ($rule->isEmptyAllowed()) {
return false;
}
}
if (!$rule->isEmptyAllowed()) {
return true;
}
}
return false;
}
/**
* Returns false if given form field described by the current entity has no errors.