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

[5.x]: Category Selection Always Overwrites #14872

Closed
theAdhocracy opened this issue Apr 26, 2024 · 9 comments
Closed

[5.x]: Category Selection Always Overwrites #14872

theAdhocracy opened this issue Apr 26, 2024 · 9 comments
Labels

Comments

@theAdhocracy
Copy link

What happened?

Description

If a category field already has a value selected, and an editor then opens the "Add category" modal and chooses any category, the original value is overwritten. In Craft 4 and prior, the overwrite would only occur if the category field was set to only allow one value. If a one-to-many relationship is allowed, the categories would be added to the existing list.

This may be related, so I'll mention it here as well, but the same issue occurs within the modal when searching, so you cannot make multiple searches to find different categories, as each search deselects previous selections.

Steps to reproduce

  1. Create a category field with no restrictions on number of relationships and implement this on an entry type.
  2. Add a category on an entry of the relevant type and save.
  3. Reopen the entry, press the "Add category" button, select any other category, and press Select.

For the secondary issue:

  1. Reopen the entry, press the "Add category" button, select any category.
  2. Now search for any other category within the modal's search input. Select any returned category.
  3. Press Select.

Expected behavior

Both the originally selected category and new category should be present.

For the secondary issue: both selected categories should now be present (the one selected prior to searching, and the one selected after).

Actual behavior

Original category is removed and only the new category is now visible.

Secondary issue: only the latter will be present.

Craft CMS version

5.0.4

PHP version

8.2.18

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@brandonkelly
Copy link
Member

I’m not able to reproduce that.

Does your Categories field have “Maintain hierarchy” enabled? What about Max Relations / Branch Limit?

Is this happening consistently for you, or only if you select certain categories?

Regarding your second bug, that’s working as expected. Only categories that are visibly selected should be added to the field when you press “Select”.

@mmikkel
Copy link
Contributor

mmikkel commented Apr 26, 2024

I'm seeing similar behavior to what @theAdhocracy describes, although in my case it only seems affect selected elements on level >1. Guessing it could be the same bug, though.

CleanShot.2024-04-26.at.22.33.50.mp4

In the above screencast, initially I've got categories on level 1, 2 and 3 from a single branch selected. The level 2 and 3 categories disappear from the field after I select a fourth category from a different branch.

Notice that in the element select modal, only the level 1 category appears to be selected. I'm guessing the bug is here; somehow the modal isn't aware of the level 2 and 3 categories being selected, which probably explains why they disappear from the field after selecting something else and clicking the Select button.

The Categories field has the "Maintain Hierarchy" setting enabled, and no branch limit. Craft 5.0.5.

Edit: Tested on a separate 5.0.5 install, and seeing the same behavior with Entries fields with the "Maintain Hierarchy" setting enabled as well.

@theAdhocracy
Copy link
Author

@brandonkelly The field has the following settings:

  • Search keywords: disabled
  • Maintain hierarchy: enabled
  • Branch limit: blank
  • View mode: "list"
  • Validate related categories: disabled
  • Allow self relations: disabled

It also has a custom Button Label and no Default Instructions.

I've been testing various combinations, and if I disable "Maintain Hierarchy" then the behaviour reverts to what we experienced in Craft 4 i.e. it doesn't overwrite. I do not believe that this setting was changed during the upgrade, but that is a possibility.

However, even with that setting disabled, we're still seeing the same, altered behaviour when using the search input to find a category. I'm not sure I understand your reasoning for this being expected behaviour, as this isn't how it worked in Craft 3 or 4.

We have categories with hundreds of possible entries. An editor needs to be able to search for them, and if they have selected it, even if the search no longer shows that specific tag, it doesn't feel intuitive to simply wipe that selection off-screen. Perhaps we're misunderstanding how the search is supposed to work, but we've always used it as a form of filtering. However, we have been considering migrating most of our categories to tags anyway, so if this is a permanent change in functionality, then perhaps that becomes a solution.

@brandonkelly
Copy link
Member

@mmikkel In that video, the “Level 2” and “Level 3” categories are selectable within the modal, even though they are already selected in the field. Guessing that’s related – for some reason the field thinks that only “Level 1” is selected, which is reflected in the modal and the normalized field value after you select the new category. @theAdhocracy are you seeing the same thing?

I’m playing around with different settings, trying to replicate, but not having any luck. Could one of you send your database backup and Composer files into support@craftcms.com by chance?

However, even with that setting disabled, we're still seeing the same, altered behaviour when using the search input to find a category. I'm not sure I understand your reasoning for this being expected behaviour, as this isn't how it worked in Craft 3 or 4.

If we’re talking about the same thing, it hasn’t changed in Craft 5 (or ever).

Here’s the behavior in Craft 4:

CleanShot.2024-04-28.at.15.21.26.mp4

@mmikkel
Copy link
Contributor

mmikkel commented Apr 29, 2024

@brandonkelly I just sent over Composer files and a DB dump to support 🙂

@theAdhocracy
Copy link
Author

@brandonkelly Apologies, I think I misunderstood what you were saying, sorry; in the past, if you first select "1" in that example, press Select, then go back in to add a new Category, search for "2", select that, then both would be selected. I thought you were saying that if you re-enter the modal and search for a new Category, that this would always have overwritten the original value, which is not the case, but I think I misread what you'd said.

As for the question of whether what I'm seeing is similar to @mmikkel, I think similar but not the same. The issue affects me on all category levels (not just level 1) and regardless of whether there is nesting at all. It's happening on all category fields where the Maintain Hierarchy toggle is enabled.

One thing I have noticed though is that once you've edited a category field once, until you Save it, the modal works as expected. E.g. in this video, you can see when the modal is first opened, the current category is not selected. If I then choose something else and press Select, it wipes the original value (which I guess makes sense, as it's no longer shown as selected, though that's not what I wanted to do). If I then reopen the modal, the new value is selected and allows me to select more.

Here's a video of one instance:
https://github.com/craftcms/cms/assets/7009462/96090bc3-0c7c-4aa2-ae7d-cbdb303e93cc

If I turn off Maintain Hierarchy, then it seems to always load the existing selection and disables it, so that the only way I can remove it is outside of the Modal. I hope that helps, sorry I can't easily provide database or composer backups, too much PID involved, but if replication is still providing problematic I can try to create a local, stripped down install and test there.

@brandonkelly
Copy link
Member

@theAdhocracy Thanks. It’s similar in that the already-selected category is still selectable within the modal, which shouldn’t be the case.

@brandonkelly
Copy link
Member

Was able to reproduce with @mmikkel’s dump. Turns out this is already fixed via #14850, which is why I couldn’t reproduce it.

@brandonkelly
Copy link
Member

Craft 5.0.6 is out now with that fix.

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

No branches or pull requests

3 participants