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

[4.x]: Error when saving Dropdown field without Default option selected #13133

Closed
gateszies opened this issue Apr 27, 2023 · 2 comments
Closed
Assignees

Comments

@gateszies
Copy link

gateszies commented Apr 27, 2023

What happened?

Entries with empty dropdown fields are not able to be saved because of 'Invalid' error.

Description

We have several Dropdown fields that do not have a Default option selected in the field settings, thus creating many entries with 'undefined' or null dropdown data. Upon updating from Craft 4.3.6.1 to 4.4.7.1, our authors noticed that when saving an entry with one of these 'empty' dropdown fields, it would now produce an error that prevented saving the entry.

I would assume that if defining a dropdown option is required for an entry to be saved, you would also be required to select a Default option when creating the field itself. However, you are able to create and define Dropdown fields with no Default option checked. Once that field is used on an entry it must be defined by the author for the entry to be saved.

Error
Screen Shot 2023-04-27 at 4 04 59 PM

Field Settings
Screen Shot 2023-04-27 at 4 05 53 PM

Steps to reproduce

  1. Create a new dropdown field. Do not check a Default option.
  2. Add your dropdown field to an entry type (existing or new)
  3. Create/navigate to an existing entry type
  4. Do not select a dropdown option as the field is not required
  5. Click Create Entry or Save Entry
  6. Empty dropdown produces an 'Invalid' error and entry cannot be saved

Expected behavior

I would expect either Craft to accept an 'empty' dropdown on an entry when no Default option is defined on the field settings. Or, if the dropdown needs to be defined, there should be a similar error when creating a new Dropdown field prompting the user to check a Default option. Otherwise, the latter scenario essentially makes any dropdown field without a Default defined in the field settings a required field for the author.

Actual behavior

Any field without a Default option defined in the field settings needs to be defined by an author. Dropdowns cannot be 'empty'. No indication of this when creating fields on the back-end.

Craft CMS version

4.4.7.1

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@i-just
Copy link
Contributor

i-just commented Apr 28, 2023

Hi, thanks for reaching out.

That’s currently the expected behaviour. We recently enhanced the validation of the dropdown fields to make sure that only values defined in the field’s settings are allowed. So in order to allow for an empty value to be saved, you should specify one in the field’s settings. Or, you can choose a default value for the field (it will only be applied to the new entries, though).

That being said, we will discuss this part internally, and I’ll provide an update afterwards:

I would assume that if defining a dropdown option is required for an entry to be saved, you would also be required to select a Default option when creating the field itself. However, you are able to create and define Dropdown fields with no Default option checked.

@brandonkelly
Copy link
Member

Craft 4.5.0 is out with an improvement to Dropdown field behavior: now if a Dropdown field’s value is invalid, and the field contains an explicit Default option, the default option will be auto-selected, and the field will be marked as changed. (#13540)

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

No branches or pull requests

3 participants