mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Validation now supports error messages on multi record forms. Added tests to support this. Closes #4499. Thanks jose_zap
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6713 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
a0af56f923
commit
7f6e54ea3a
2 changed files with 24 additions and 0 deletions
|
@ -382,6 +382,15 @@ class FormHelper extends AppHelper {
|
|||
$options = array_merge(array('wrap' => true, 'class' => 'error-message', 'escape' => true), $options);
|
||||
|
||||
if ($error = $this->tagIsInvalid()) {
|
||||
if (is_array($error)) {
|
||||
list(,,$field) = explode('.', $field);
|
||||
if (isset($error[$field])) {
|
||||
$error = $error[$field];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($text) && is_numeric($error) && $error > 0) {
|
||||
$error--;
|
||||
}
|
||||
|
|
|
@ -533,6 +533,21 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertPattern('/<div[^<>]*class="error-message"[^<>]*>You must provide a URL<\/div>/', $result);
|
||||
}
|
||||
|
||||
function testMultipleInputValidation() {
|
||||
$this->Form->create();
|
||||
$this->Form->validationErrors['Address'][0]['title'] = 'This field cannot be empty';
|
||||
$this->Form->validationErrors['Address'][0]['first_name'] = 'This field cannot be empty';
|
||||
$this->Form->validationErrors['Address'][1]['last_name'] = 'You must have a last name';
|
||||
$result = $this->Form->input('Address.0.title');
|
||||
$this->assertPattern('/<div[^<>]*class="error-message"[^<>]*>This field cannot be empty<\/div>/', $result);
|
||||
$result = $this->Form->input('Address.0.first_name');
|
||||
$this->assertPattern('/<div[^<>]*class="error-message"[^<>]*>This field cannot be empty<\/div>/', $result);
|
||||
$result = $this->Form->input('Address.0.last_name');
|
||||
$this->assertNoPattern('/<div[^<>]*class="error-message"[^<>]*>.*<\/div>/', $result);
|
||||
$result = $this->Form->input('Address.1.last_name');
|
||||
$this->assertPattern('/<div[^<>]*class="error-message"[^<>]*>You must have a last name<\/div>/', $result);
|
||||
}
|
||||
|
||||
function testFormInput() {
|
||||
$result = $this->Form->input('Contact.email', array('id' => 'custom'));
|
||||
$expected = '<div class="input"><label for="custom">Email</label><input name="data[Contact][email]" type="text" id="custom" value="" /></div>';
|
||||
|
|
Loading…
Add table
Reference in a new issue