Merge pull request #4779 from kinglozzer/pulls/fieldgroup-composite-validation

FIX: Hidden errors for composite fields nested inside FieldGroups (fixes #4773)
This commit is contained in:
Damian Mooyman 2015-11-19 14:04:41 +13:00
commit 83ede291bd
2 changed files with 24 additions and 2 deletions

View File

@ -118,7 +118,8 @@ class FieldGroup extends CompositeField {
* @return string
*/
public function Message() {
$fs = $this->FieldList();
$fs = array();
$this->collateDataFields($fs);
foreach($fs as $subfield) {
if($m = $subfield->Message()) $message[] = rtrim($m, ".");
@ -131,7 +132,8 @@ class FieldGroup extends CompositeField {
* @return string
*/
public function MessageType() {
$fs = $this->FieldList();
$fs = array();
$this->collateDataFields($fs);
foreach($fs as $subfield) {
if($m = $subfield->MessageType()) $MessageType[] = $m;

View File

@ -0,0 +1,20 @@
<?php
class FieldGroupTest extends SapphireTest {
public function testMessagesInsideNestedCompositeFields() {
$fieldGroup = new FieldGroup(
new CompositeField(
$textField = new TextField('TestField', 'Test Field'),
$emailField = new EmailField('TestEmailField', 'Test Email Field')
)
);
$textField->setError('Test error message', 'warning');
$emailField->setError('Test error message', 'error');
$this->assertEquals('Test error message, Test error message.', $fieldGroup->Message());
$this->assertEquals('warning. error', $fieldGroup->MessageType());
}
}