Programmatically toggling checkboxes in the control panel. #9200
-
I have a fieldset with a Checkboxes fieldtype. It contains a bunch of countries. I have a button, what I want it to do is select all EU countries within the Checkboxes fieldtype. I can utilize something like After some research I stumbled across hooks. They kind of do what I want. But there is a problem / I don't know how to correctly do this. When the button is clicked there is a piece of code that hooks into the It only works if the hook is the last thing firing, but since that is controlled by the user, I can't know that, therefore the data will never be accurate. What I have (that works):
What I want (but don't know how to properly do)
Any pointers would be very helpful. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I managed to fix this by myself. I ended up tracking all changes for checkboxes within the countries Checkboxes fieldtype. This also means that upon saving, all the correct values will be checked even if the EU button is clicked at the start and not right before saving. |
Beta Was this translation helpful? Give feedback.
I managed to fix this by myself.
I ended up tracking all changes for checkboxes within the countries Checkboxes fieldtype.
Then upon saving of the entry, using the
entry.saving
hook, I overwrite the countries key in the payload in order to have al the checked checkboxes present.This also means that upon saving, all the correct values will be checked even if the EU button is clicked at the start and not right before saving.