-
Notifications
You must be signed in to change notification settings - Fork 823
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
Single select field empty value validation with integer values #11502
Comments
What specific changes in CMS 5.3 are causing this? It sounds like you've got some additional context that isn't included here. There's no change to the It's also interesting that this isn't reproducible without being inside an inline-editable elemental block. That suggests to me that the bug is more likely to have been introduced by a change in elemental than by a change in framework. |
Having played around with this a bit, I can confirm the following:
|
Linked PR has been merged, it will be automatically tagged shortly |
Module version(s) affected
5.3.3
Description
Form field validation enhancements that were introduced in CMS 5.3 are causing unexpected issues in some specific cases. I'll showcase this on a
DropDownField
but it's possible that other fields that extendSingleSelectField
are also impacted.If a
DropDownField
is used with integer values and the field allows empty default (allows a value to not be provided) the form validation will not accept the empty value.How to reproduce
My code sample uses a content block but I don't think this issues is related to Elemental, I just need to have the inline editing context.
Int
type DB fieldDropDownField
for the DB field and provide some test valuesExpected outcome
The changes get saved without validation message as empty value is valid (we don't have any validation set up)/
Actual outcome
Field validation message pops up and prevents the changes to be saved.
Code snippets
Possible Solution
The issue comes from the validation code in
SingleSelectField::validate()
. The empty values comes in as'0'
(string) which is not considered an empty value. It's likely that casting this value as an integer would solve the issue.Tried several other possible values (passed via the
$values
) but neither one worked:0
-1
''
Additional Context
We had similar issues with
RequiredFields
validator where we ended up changing the validation comparison method:Not sure if this is related though. I'm just illustrating that the condition to determine that value is empty needs a refinement.
Validations
silverstripe/installer
(with any code examples you've provided)PRs
The text was updated successfully, but these errors were encountered: