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] Fix typeahead relationship input corrupting data #11059

Merged
merged 2 commits into from
Nov 5, 2024

Conversation

daun
Copy link
Contributor

@daun daun commented Nov 5, 2024

When creating new taxonomy terms in a typeahead select, it currently allows creating new terms even if that term already exists. Both the existing as well as the newly created term can be selected and submitted. On save, the data is deduplicated, but the keys aren't reset. The resulting data structure is now an array with skipped keys, which in JSON turns into an object, and the input refuses to display the data. See issue #11019 for details and screenshots.

This PR fixes the latter part (the corrupted data and broken input state) by always making sure that relationship field data is returned as a list, without skipping array keys.

Partially closes #11019.

@jasonvarga
Copy link
Member

Instead of what you did, I think if we just add ->values() between these two lines, the problem is solved too.

->unique()
->all();

Could you confirm?

@daun
Copy link
Contributor Author

daun commented Nov 5, 2024

@jasonvarga That seems to work! I've pushed your suggested fix.

@jasonvarga
Copy link
Member

Thanks!

@jasonvarga jasonvarga merged commit 44ea6dc into statamic:5.x Nov 5, 2024
16 checks passed
@daun daun deleted the fix/term-typeahead-input-duplicates branch November 5, 2024 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typeahead field shows duplicate terms and corrupts data on save
2 participants