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.2.3]: Multiple fields with the same name cause issues with entry filters #11881

Closed
MoritzLost opened this issue Sep 5, 2022 · 3 comments
Closed

Comments

@MoritzLost
Copy link
Contributor

What happened?

Description

The new entry filters (conditionals) seem to have an issue if there are multiple fields with the same name.

A bit of background: We have a section with five entry types. There's one separate category group corresponding to each entry type, and there are five category fields for the five category groups. Each of the five entry types in the section uses the category field linked to the category group it belongs to. For usability reasons, those five fields are all named identically (Angebotsart, which means something like Offer type in German).

Unfortunately, Craft only displays one field with this name in the filters dropdown:

filter_offer_type

There should be five fields named Angebotsart in the dropdown, but there's only one. I assume those fields are somehow collapsed to a single one to improve readability? But this doesn't make sense, because now you can only filter by one of the five category groups, and there's no way to filter by the other category groups.

We use the built-in source view for the section and have added five custom sources, one for each of the entry types. This issue occurs in all of those sources. So every custom source that is limited to one entry type only has the field for the first entry type in the section as a filter available. Of course, adding any filter yields zero results for those sources, because the field relating to that group is not used in those entry types.

Steps to reproduce

  1. Add multiple category groups.
  2. Add one category field for each category group and give all fields the same name. Add a section with one entry type for each category group, and add the category field for this group to the field layout of each entry type.
  3. Open the filters dropdown in the entries list. It will only show one of the category fields, and only allow you to filter by one of the category groups.

Expected behavior

I should see all fields in the filters dropdown. In my screenshot above, there should be five fields named Angebotsart. Of course this is not ideal, since there's no way to tell which field is which. But that's better than the alternative, not being able to filter by those fields at all.

Some additional ideas:

  • In an ideal world, Craft would detect that there are multiple fields using the same name and display something to differentiate them. For example, it could show the field handle, field ID or list the entry type(s) they're used in.
  • Arguably, a custom source that's limited to one particular entry type should only show the fields that are available in that entry type's field layout. Though I understand that that may be difficult to implement.

Actual behavior

Having multiple fields with the same name causes the filters dropdown to only show one of them.

Craft CMS version

4.2.3

PHP version

8.1

Operating system and version

No response

Database type and version

MySQL 8

Image driver and version

No response

Installed plugins and versions

No response

@brandonkelly
Copy link
Member

This is working as expected – it would be completely unclear which “Angebotsart” option refers to which field if we showed duplicate option labels. So the condition builder will intentionally filter out any duplicates.

To work around this, give each of your fields a unique name. You can then override their labels to each just say “Angebotsart” by editing the fields’ settings within their respective field layouts.

@brandonkelly brandonkelly closed this as not planned Won't fix, can't repro, duplicate, stale Sep 7, 2022
@MoritzLost
Copy link
Contributor Author

@brandonkelly Thanks for the explanation!

I understand the reasoning behind this feature, though I'm not sure that I agree with the conclusion. Having multiple fields with the same name in the dropdown is confusing, yes, but having fields missing is even more confusing. In this case, our client expected to be able to select from all the five category trees when selecting Angebotsart, and were confused why only one of them was available. Having five Angebotsart fields available in the dropdown would of course be a bit confusing, but would be usable at least, even with a bit of trial and error.

To work around this, give each of your fields a unique name. You can then override their labels to each just say “Angebotsart” by editing the fields’ settings within their respective field layouts.

We're doing that now, and it's an acceptable solution in many cases. But I would argue there are definitely valid reasons/use-cases to have multiple fields with the same name. Giving the fields different names and overriding that in the field layout is not a good solution in this case, because it will be even more confusing to the client if the field has a different name in the filters dropdown than it does in the entry form.

I think a better solution would be to display more information in the filters dropdown (field handle or the entry types the field is used in) to make them uniquely identifiable. Can I open a discussion for that feature request or should I consider this issue firmly closed? 👀

@brandonkelly
Copy link
Member

@MoritzLost You’re welcome to propose a specific idea of what you’d like to see in a new discussion. But that would be a feature request we’d have to consider down the road. The issue as it stands is firmly closed because it’s working as expected.

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

2 participants