Not allowing new value if certain value is selected as option (multiselect)
I am trying to use multiselect but when a certain value is selected, I want the user to not be able to add a new values unless they delete the previous one. Is this possible?
For context, I am making a Post form that could make them with or without tags. I want to show them together in my homepage with Eager Loading, my solution is to add "No tags" as an actual tag (though it is not shown), so I can use "with" on my query.
So in the Post form when selecting "No tags" as tag they should not be able to add another tags.
9 Replies
why though?
whats wrong with just selecting no tags
Yeah it is doable, however it is to prevent wrong interaction when adding new tags if already selected no tags. Another solution would be to mutate the data then delete other tags before saving, or to validate before saving. But I'm trying to find a way for it to visually work in the user so they won't be able to even do it.
Maybe it is too complicated, if it is then I would just go the other solution
i dont understand why its a wrong interaction
you select tags if you want them
i think youre really overthinking this? but maybe I misunderstand what youre trying to do
Sorry for the confusion,
The interaction:
1. User select "No Tags" as tag (same multiselect field)
2. Now the field is only "No Tags".
3. User shouldnt be able to add new tags like 'Event' so the field can become "No Tags, Event" (It's like you cant add existing tag as new tag kind of interaction)
Also I try another approach that is to create another field for bool (Use tags, yes/no), then I use
$get
to check value from the other fields in the multiselect ->disabled
if it is No tags. This is currently the working one and maybe closer to what you are understanding from before. Maybe i can also add afterStateUpdated
to $set any existing value to only "No tags" if another tags already existi understand all of that
i dont understand why you would have a tag called No Tags
whats the point
they just dont need to select any tags
Exactly and no tags would be shown in the frontend is null... It's a standard query
I’m with Dan on this one. I don’t understand the need to set it to no tags vs just not adding any tags.
if you are adamant on assigning a no-tags tag, mutate before save, and apply the tag no-tags if no tags exist
Thanks for all the responses. For now I'm going with the disabled field and mutation just in case something is wrong with the set values.
This could also be a query problem, I will look more into that.