diff --git a/code/Company.php b/code/Company.php index c1cd974..6356f1b 100644 --- a/code/Company.php +++ b/code/Company.php @@ -13,6 +13,7 @@ use SilverStripe\Versioned\Versioned; use RelationFieldsTestPage; use GridFieldTestPage; +use SilverStripe\Forms\RequiredFields; /** * @@ -100,15 +101,11 @@ public function getCMSFields() 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() diff --git a/code/Employee.php b/code/Employee.php index 8caa708..cb0ee06 100644 --- a/code/Employee.php +++ b/code/Employee.php @@ -5,6 +5,7 @@ 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 @@ public function requireDefaultRecords() 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'] + ); } /**