-
Notifications
You must be signed in to change notification settings - Fork 96
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
TreeDropdownField fails to validate after clearing value in react forms #1576
Comments
Just to clarify, you have a link to code in the |
I don't want to test this with linkfield as that's not a supported module and I'm not familiar with its code.
Can you please provide me with reproduction instructions for setting this up without using linkfield? Could be in asset-admin or possible elemental inline-editable block if that uses the formbuilder. |
I confirm, this is the issue in CMS4 and CMS5 as well. |
ah great thanks @sabina-talipova I was having some trouble getting it going in another place! |
Relates to silverstripe/silverstripe-elemental#329 |
We spent half an hour arguing about what the proper empty value should be and coludn't reach a sensible decision. We'll create a SPIKE to review the option and wider implications. |
When using a Treedropdownfield in a react form (eg the Linkfield Module SiteTreeLink) the field will pass a 'required' validation if the field is cleared - even though this should reset the field to an 'empty' state.
Steps to reproduce:
silverstripe/linkfield
Investigation
it seems that when clearing the field it gets set to a value of
0
https://github.com/silverstripe/silverstripe-admin/blob/2/client/src/components/TreeDropdownField/TreeDropdownField.js#L425 which at some point gets converted to a string.This means that when Validator.js checks the value of the field it sees
'0'
and this passes the 'required' validation rule as it is a non-empty string:by contrast, when the field loads - the value is
""
Seems we should find another way to clear the field to an empty string instead of
0
.If I update
SINGLE_EMPTY_VALUE
to equal""
then the validation works as expectedthis was tested on v 4.13.1 of the admin module - unsure if this is still a problem in v5 at this stage.
Acceptance criteria
PR
The text was updated successfully, but these errors were encountered: