Issue with Model based Dictionary Field for Multiple Selections in User Blueprint #11198
Unanswered
chano195
asked this question in
Troubleshooting
Replies: 1 comment
-
I've tried to replicate your setup as best I can from your screenshots, but it seems to be working as expected for me. 🤔 Are you able to replicate the issue in a fresh Statamic site? Also, is there any specific reason you're doing |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Bug description
I am encountering an issue with a dictionary (modules) that is based on a model in my database, configured as described in the Statamic documentation here.
In my user blueprint, I have a field of type dictionary associated with the modules dictionary for multiple selections. Everything works fine when saving, and it stores the selected modules in the users table under the modules field as an array, like this: ["1","2"], where 1 and 2 are the IDs of the selected modules based on the modules model.
However, when I return to edit the user, the labels of the selected modules do not appear, and the saved format (["1","2"]) is not recognized correctly. The options do not appear as selected, and the saved data does not show up as expected in the user interface.
I've also tested using a pivot table between the module and user models, but it not works for me
Questions/Clarifications:
Is this the best approach for implementing this feature, or are there better ways to associate users with multiple modules?
Do you have any suggestions or corrections to ensure that the selected module labels display correctly when editing the user?
I would appreciate any guidance on how to resolve this. Thank you in advance!
Model based Dictionary:
User BluePrint:
User Model
Editor selector (working):
Editor bug
How to reproduce
Create a Dictionary:
Create a dictionary (modules) based on a model as described in the Statamic documentation.
The dictionary should use a model where the id is the key and nombre (or another attribute) is the value. Example fields could include:
id (primary key)
nombre (name of the module)
Create a User Field for Module Association:
In your user model (or the relevant model), create a field called modulo_id to store the associated module IDs. This will act as the foreign key to your modules dictionary.
Create a Blueprint for Users:
Create a blueprint for the user model of type dictionary that references the modules dictionary. Make sure the field type is set for multiple selection, with no selection limit.
Create or Edit a User:
Create a new user or edit an existing one in the Statamic control panel.
In the modulo_id field, select one or more modules from the available options. This should work fine and save the selected module(s) as an array (e.g., ["1","2"]) in the user’s modulo_id field.
Exit and Re-enter the User Edit View:
Save the user and exit the edit view.
Return to the user edit screen for the same user.
Expected Behavior:
When re-editing the user, the previously selected modules should be displayed as selected options with their labels.
Actual Behavior:
The selected modules now appear as ["1","2"] in the modulo_id field, marked in red. It appears as if the user can only select a single option, instead of multiple options being properly displayed.
As seen in the provided screenshots, the field behaves as if it’s a single selection, which causes confusion.
Logs
No response
Environment
Installation
Fresh statamic/statamic site via CLI
Additional details
Please let me know if you need anything else, I'll be on the lookout
Beta Was this translation helpful? Give feedback.
All reactions