Cms: Dropdowns - all options marked as default

Created on 9 Sep 2020  Â·  8Comments  Â·  Source: craftcms/cms

Description

Just came across this issue with a matrix field we're using for content building across a site. On new entries, the dropdown options are not respecting the default value - it defaults to the first option in the list.

Upon reviewing the field settings for the matrix block, all of the options are checked as default. When editing the field to choose a single default value, the change is reverted back to all selected after saving.

Screen Shot 2020-09-09 at 10 47 57 AM

This is just one of about 30 dropdowns within this matrix field with the issue.

Additional info

  • Craft version: Craft Pro 3.4.26
  • PHP version: 7.1.33
  • Database driver & version: MySQL 5.6.43
bug

All 8 comments

This is occurring on a standard dropdown field as well, so doesn't seem to be tied to matrix fields.

These checkboxes should be radio checkboxes in my opinion, or am I overlooking something?

I’m not able to reproduce this; only able to select one Default option at a time. Are you getting any JavaScript errors on the page?

These checkboxes should be radio checkboxes in my opinion, or am I overlooking something?

@Wiejeben It’s not possible to deselect a radio button.

@brandonkelly I'm not seeing any errors upon loading, altering or saving the page. I've looked back at some backups and staging servers and found this started in the last 10 days - during which no Craft or plugin updates have been installed. A few new redactor and plain text fields were added, but no changes were made to any dropdown or matrix fields with dropdowns. So something seems to have gone amiss with the DB.

Is there a way to check the values in the DB?

Not really sure what could go wrong in the DB. If you uncheck all the Default checkboxes and then start checking new ones, does it behave as expected (only one selected at a time)?

So I found the field in the DB. The settings are stored as follows, with the option value also being inserted as the default value:

{"optgroups":true,"options":[{"label":"1/4","value":"1-of-4","default":"1-of-4"},{"label":"1/3","value":"1-of-3","default":"1-of-3"},{"label":"1/2","value":"1-of-2","default":"1-of-2"},{"label":"2/3","value":"2-of-3","default":"2-of-3"},{"label":"3/4","value":"3-of-4","default":"3-of-4"}]}

Comparing this to a working version of the field, it looks as though the default value should be "default":"1" and blank for all other options. I can update the DB entry as such:

{"optgroups":true,"options":[{"label":"1/4","value":"1-of-4","default":""},{"label":"1/3","value":"1-of-3","default":""},{"label":"1/2","value":"1-of-2","default":"1"},{"label":"2/3","value":"2-of-3","default":""},{"label":"3/4","value":"3-of-4","default":""}]}

This then shows the expected results in Craft:

Screen Shot 2020-09-10 at 5 07 07 PM

However, saving the field in the control panel (with or without making a change), cause all options to be marked as default again. With the first code block back in the DB settings.

Weird… your option values are getting saved to the default keys. Not sure how that could be happening, and not able to reproduce. Can you try updating Craft CMS?

Upgrading Craft allowed the fields to be resaved with the correct default values, resolving the issue.

Was this page helpful?
0 / 5 - 0 ratings