diff --git a/src/StringTagField.php b/src/StringTagField.php index 81abe03..adf42d7 100644 --- a/src/StringTagField.php +++ b/src/StringTagField.php @@ -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. @@ -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 */ @@ -369,18 +375,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 */ diff --git a/src/TagField.php b/src/TagField.php index 317635c..ba6025d 100644 --- a/src/TagField.php +++ b/src/TagField.php @@ -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; @@ -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. @@ -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 */ @@ -563,18 +569,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. *