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

Improve invalid Dropdown value behavior #13540

Conversation

brandonkelly
Copy link
Member

@brandonkelly brandonkelly commented Aug 10, 2023

Description

Improves the behavior of Dropdown fields when their value is invalid.

As of 4.4, invalid Dropdown fields which didn’t have a blank option would get a blank option prepended, and that would be selected by default in the UI (see #12235 (comment)). This would lead to a validation error on save (because a blank value wasn’t one of the allowed options), forcing the author to make a valid selection.

That confused authors because they were getting validation errors for fields they hadn’t even edited.

With this PR, invalid Dropdown fields which have a default option will now automatically select that instead, and the field will immediately be marked at changed, to indicate that the selected option is not equal to the field’s actual current value, until it’s saved.

A Dropdown field that is marked as changed

Related issues

@linear
Copy link

linear bot commented Aug 10, 2023

DEV-1118 Set Dropdown inputs to the default value when invalid

When a Dropdown field’s value is invalid, it should be reassigned to its default value (and marked as changed).

@northform
Copy link

I've a multisite that was recently updated to 4.5.3 and there are certain select fields which have values assigned to them but they are hitting validation errors.

image

The errors seem to take you in an infinite loop between the sites, so editing Site A shows a validation error for Site B, then when you go to resave Site B, it shoes a validation error for Site C etc.

@brandonkelly
Copy link
Member Author

@northform Could you send your Composer files and a database backup over to support@craftcms.com so we can reproduce and look into it from there?

@elivz
Copy link

elivz commented Sep 25, 2023

I'm running into the same issue as @northform. I am having a hard time putting my finger on exactly what is going on, but I think it has to do with a dropdown field being invalid in two different sites. Craft seems to only "fix" the current site to the default option, but having that invalid value in the other site nevertheless prevents the current site from being saved, so there is no way to update either one of them.

@brandonkelly
Copy link
Member Author

@elivz Cross site validation behavior is improving in the next release (see #13675 (comment)). Maybe it will solve that for you?

@elivz
Copy link

elivz commented Sep 26, 2023

Sounds like it should, in theory anyway. Right now I have some pages that are stuck in a state where they are impossible to update short of fiddling with the raw data in the DB, so anything will be an improvement!

@brandonkelly
Copy link
Member Author

Any chance you have time to test in the next few minutes as I’m preparing the release? If so and it turns out to still be a problem for you, I could try to improve it further.

If you can, then change your craftcms/cms requirement to dev-develop as 4.5.5, and run composer update.

@elivz
Copy link

elivz commented Sep 26, 2023

Works now for me! On an entry where I was previously stuck in that validation loop between two sites, I am now able to save each site separately, which updates the dropdown fields to their default values. No errors or other issues. Thanks!

@brandonkelly
Copy link
Member Author

Awesome, thanks so much for checking!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants