Single choice toggles
Hello everyone!
I am trying to implement single choice toggle. A bit of context
I have product edit page.
On product page, there is a tab with all media assigned to the product (repeater)
Each row has FileUpload (media itself)
and few toggles. One of them is "is_cover".
The idea behind it is that only one media can be selected as "Cover"
currently it's implemented as:
That works. But it's painfully and unnecessary slow...
I was thinking to use radio, but radio can not be split in repeater. All options must be provided at once in one place. Therefore not suitable in my use - case π
All my attempts to move logic on front-end failed.
I was able to subscribe for event via:
'x-init' and using $watch("state", value => { ... } (maybe there is more efficient way of doing that)
But after than, i was not able to receive items from repeater to toggle off existed records ...
Any documentation or tips, please?
Thanks!
Solution:Jump to solution
Just make the toggle field ->distinct() in the repeater. Then it will throw a validation error and the user has to fix it.
2 Replies
Solution
Just make the toggle field ->distinct() in the repeater. Then it will throw a validation error and the user has to fix it.
Thank you very much, @awcodes that's exactly what I was looking for!