diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 65f626934..251baf689 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -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--; } diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index f5684e4c0..371f04f90 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -533,6 +533,21 @@ class FormHelperTest extends CakeTestCase { $this->assertPattern('/]*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('/]*class="error-message"[^<>]*>This field cannot be empty<\/div>/', $result); + $result = $this->Form->input('Address.0.first_name'); + $this->assertPattern('/]*class="error-message"[^<>]*>This field cannot be empty<\/div>/', $result); + $result = $this->Form->input('Address.0.last_name'); + $this->assertNoPattern('/]*class="error-message"[^<>]*>.*<\/div>/', $result); + $result = $this->Form->input('Address.1.last_name'); + $this->assertPattern('/]*class="error-message"[^<>]*>You must have a last name<\/div>/', $result); + } + function testFormInput() { $result = $this->Form->input('Contact.email', array('id' => 'custom')); $expected = '
';