Skip to content

Commit

Permalink
Merge pull request #146 from creative-commoners/pulls/0.4/employee-va…
Browse files Browse the repository at this point in the history
…lidation

MNT Make employee validatable
  • Loading branch information
sabina-talipova authored Aug 9, 2023
2 parents c8a20ee + 39b85c9 commit 535faef
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion code/Employee.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SilverStripe\FrameworkTest\Model;

use SilverStripe\Assets\Image;
use SilverStripe\Forms\EmailField;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\Connect\MySQLSchemaManager;
Expand All @@ -27,6 +28,7 @@ class Employee extends DataObject

private static $db = array(
'Name' => 'Varchar',
'Email' => 'Varchar',
'Biography' => 'HTMLText',
'DateOfBirth' => 'Date',
'Category' => 'Enum("marketing,management,rnd,hr")'
Expand Down Expand Up @@ -90,6 +92,7 @@ public function getCMSFields()
{
// Use basic scaffolder (no tabs)
$fields = $this->scaffoldFormFields();
$fields->replaceField('Email', EmailField::create('Email'));
$fields->push(new NumericField('ManyMany[YearStart]', 'Year started (3.1, many-many only)'));
$fields->push(new TextField('ManyMany[Role]', 'Role (3.1, many-many only)'));
return $fields;
Expand Down Expand Up @@ -142,7 +145,7 @@ public function validate()
{
$result = parent::validate();
if (!$this->Name) {
$result->error('"Name" can\'t be blank');
$result->addFieldError('Name', '"Name" can\'t be blank');
}
return $result;
}
Expand Down

0 comments on commit 535faef

Please sign in to comment.