Skip to content

Commit

Permalink
Merge pull request #158 from creative-commoners/pulls/0.4/toast-msg-g…
Browse files Browse the repository at this point in the history
…ridfield

MNT Add custom validator for test cases
  • Loading branch information
GuySartorelli authored Nov 12, 2023
2 parents a5aeaa3 + 3f03425 commit 6637e88
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
13 changes: 5 additions & 8 deletions code/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SilverStripe\Versioned\Versioned;
use RelationFieldsTestPage;
use GridFieldTestPage;
use SilverStripe\Forms\RequiredFields;

/**
*
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 5 additions & 6 deletions code/Employee.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']
);
}

/**
Expand Down

0 comments on commit 6637e88

Please sign in to comment.