Merge pull request #849 from josepereira245/issue/833

FIX: Fixes #833 added validation for minimum and maximum length
This commit is contained in:
Guy Marriott 2019-01-16 15:57:46 +13:00 committed by GitHub
commit 305cf39b32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -101,6 +101,23 @@ class EditableTextField extends EditableFormField
return parent::getCMSFields();
}
/**
* @return ValidationResult
*/
public function validate()
{
$result = parent::validate();
if ($this->MinLength > $this->MaxLength) {
$result->addError(_t(
__CLASS__ . 'MINMAXLENGTHCHECK',
'Minimum length should be less than the Maximum length.'
));
}
return $result;
}
/**
* @return FieldList
*/
@ -115,6 +132,7 @@ class EditableTextField extends EditableFormField
NumericField::create('MinLength', false),
LiteralField::create('RangeLength', _t(__CLASS__.".RANGE_TO", "to")),
NumericField::create('MaxLength', false)
]
)
]);

View File

@ -208,6 +208,7 @@ en:
RANGE_TO: to
SINGULARNAME: 'Text Field'
TEXTLENGTH: 'Allowed text length'
MINMAXLENGTHCHECK: 'Minimum length should be less than the Maximum length.'
SilverStripe\UserForms\Model\EditableFormField\Validator:
REQUIRED_ERROR: 'Form fields cannot be required and have conditional display rules.'
SilverStripe\UserForms\Model\Recipient\EmailRecipient: