Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Disable ancestor FieldValidators #311

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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