From 62e771e3d543fe04306a2b5884e7cf6c6fdf3d14 Mon Sep 17 00:00:00 2001 From: Sabina Talipova Date: Thu, 2 Nov 2023 13:29:31 +1300 Subject: [PATCH] MNT Add custom validator for test cases --- code/Company.php | 8 ++++++++ code/Employee.php | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/code/Company.php b/code/Company.php index c1cd974..42d1fda 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,6 +101,13 @@ public function getCMSFields() return $fields; } + public function getCMSValidator() + { + return new RequiredFields( + ['Name'] + ); + } + public function validate() { $result = parent::validate(); diff --git a/code/Employee.php b/code/Employee.php index 8caa708..b7f2a4e 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,6 +142,13 @@ public function requireDefaultRecords() srand(); } + public function getCMSValidator() + { + return new RequiredFields( + ['Name'] + ); + } + public function validate() { $result = parent::validate();