Skip to content

Commit

Permalink
Merge pull request #311 from creative-commoners/pulls/4/form-field-valid
Browse files Browse the repository at this point in the history
API Disable ancestor FieldValidators
  • Loading branch information
GuySartorelli authored Dec 2, 2024
2 parents 7f50ea1 + 8d97a7a commit 195c6bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
20 changes: 7 additions & 13 deletions src/StringTagField.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\Validator;
use SilverStripe\Model\List\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataObjectInterface;
use SilverStripe\Model\List\SS_List;
use SilverStripe\Model\ArrayData;
use SilverStripe\View\Requirements;
use SilverStripe\Core\Validation\FieldValidation\OptionFieldValidator;

/**
* Provides a tagging interface, storing comma-delimited tags in a DataObject string field.
Expand All @@ -26,6 +26,12 @@
*/
class StringTagField extends DropdownField
{
private static array $field_validators = [
// Disable validation as StringTagField is a special case where labels can be the values
// rather than the keys always being the values - for instance when creating new tags
OptionFieldValidator::class => null,
];

/**
* @var array
*/
Expand Down Expand Up @@ -356,18 +362,6 @@ protected function getTags($term)
return array_slice(array_values($items ?? []), 0, $this->getLazyLoadItemLimit());
}

/**
* DropdownField assumes value will be a scalar so we must
* override validate. This only applies to Silverstripe 3.2+
*
* @param Validator $validator
* @return bool
*/
public function validate($validator)
{
return $this->extendValidationResult(true, $validator);
}

/**
* @return bool
*/
Expand Down
20 changes: 7 additions & 13 deletions src/TagField.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\MultiSelectField;
use SilverStripe\Forms\Validator;
use SilverStripe\Model\List\ArrayList;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
Expand All @@ -17,6 +16,7 @@
use SilverStripe\ORM\Relation;
use SilverStripe\Model\List\SS_List;
use SilverStripe\Model\ArrayData;
use SilverStripe\Core\Validation\FieldValidation\MultiOptionFieldValidator;

/**
* Provides a tagging interface, storing links between tag DataObjects and a parent DataObject.
Expand All @@ -26,6 +26,12 @@
*/
class TagField extends MultiSelectField
{
private static array $field_validators = [
// Disable validation as TagField is a special case where labels can be the values
// rather than the keys always being the values - for instance when creating new tags
MultiOptionFieldValidator::class => null,
];

/**
* @var array
*/
Expand Down Expand Up @@ -562,18 +568,6 @@ protected function getTags($term)
return array_values($items ?? []);
}

/**
* DropdownField assumes value will be a scalar so we must
* override validate. This only applies to Silverstripe 3.2+
*
* @param Validator $validator
* @return bool
*/
public function validate($validator)
{
return $this->extendValidationResult(true, $validator);
}

/**
* Converts the field to a readonly variant.
*
Expand Down

0 comments on commit 195c6bd

Please sign in to comment.