Switching entry types loads fields without honouring their defaults.
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.6k
- Forks
- 705
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 134
Description
Description
If I create a radio button field with two options, mark one as the default and put it in a structure entry type's field layout when I create a new entry in the structure the option is not pre-selected if the entry type is not the default.
I think this might be down to the drafts system having pre-saved the entry (and the field value as empty as it's not in the default type's field layout) before changing the type, so it's (re-)loading the field with nothing selected.
If the entry is "new" (so not dirty) I would expect the draft not to save it when you change entry type?
I'm not sure if it's the same bug or another (or the cause of this one) but another thing that happens, I suspect because of the draft being saved, is that the non-default entry type inherits the "first" title if it's auto-generated. My default type auto-generates the title based on other field values but my non-default type allows you to fill in the title field yourself. Changing to the second entry type, for a new entry, pulls the auto-generated title over (which makes no sense for the entry type)
Steps to reproduce
- Create a structure section and create two entry types (set the default type's title field to be auto-generated to anything you like, "This Entry Is The Default Type" should work nicely. Show the title field on the second entry type.)
- Create a radio button field with 2 values, mark one as the default value.
- Put this field in the non-default entry type's field layout.
- Create a new entry in the channel.
- Select the second entry type (and watch it save the draft before changing the entry type)
- Observe field has loaded in with no default value checked and title is generated from the wrong type instead of blank.
Additional info
- Craft version: 3.4.17.1
- PHP version: 7.4
- Database driver & version: MySQL 8.0.18
- Plugins & versions:
Conditional Fields 0.0.6
Super Table 2.4.9
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files or tests are named. Reproduce issue 5987 and trace the entry-type switching and draft-save flow described in the steps. Done means changing a new entry type preserves that type’s field defaults and does not carry over the previous type’s generated title.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend, content
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100