mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 11:06:02 +02:00
MNT Add custom validator for test cases
This commit is contained in:
parent
a5aeaa3380
commit
3f03425c67
@ -13,6 +13,7 @@ use SilverStripe\Versioned\RecursivePublishable;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use RelationFieldsTestPage;
|
||||
use GridFieldTestPage;
|
||||
use SilverStripe\Forms\RequiredFields;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -100,15 +101,11 @@ class Company extends DataObject
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function validate()
|
||||
public function getCMSValidator()
|
||||
{
|
||||
$result = parent::validate();
|
||||
|
||||
if (!$this->Name) {
|
||||
$result->addFieldError('Name', 'Name is required');
|
||||
}
|
||||
|
||||
return $result;
|
||||
return new RequiredFields(
|
||||
['Name']
|
||||
);
|
||||
}
|
||||
|
||||
public function DynamicProperty()
|
||||
|
@ -5,6 +5,7 @@ namespace SilverStripe\FrameworkTest\Model;
|
||||
use SilverStripe\Assets\Image;
|
||||
use SilverStripe\Forms\EmailField;
|
||||
use SilverStripe\Forms\NumericField;
|
||||
use SilverStripe\Forms\RequiredFields;
|
||||
use SilverStripe\Forms\TextField;
|
||||
use SilverStripe\ORM\Connect\MySQLSchemaManager;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
@ -141,13 +142,11 @@ class Employee extends DataObject
|
||||
srand();
|
||||
}
|
||||
|
||||
public function validate()
|
||||
public function getCMSValidator()
|
||||
{
|
||||
$result = parent::validate();
|
||||
if (!$this->Name) {
|
||||
$result->addFieldError('Name', '"Name" can\'t be blank');
|
||||
}
|
||||
return $result;
|
||||
return new RequiredFields(
|
||||
['Name']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user