Is there a way to update defaultValue using an onChange handler? #526
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello, I also used a checkbox with select/unselect all, with the idea of iterating over every checkbox and setting the current value via form.update : const toggleSelectAll = (check: boolean) => {
permissions.getFieldList().forEach((permission) => {
const { active } = permission.getFieldset();
form.update({ name: active.name, value: check });
});
}; Maybe with your schema you will have to extract { actions } from permissions, and then get another fieldList and fieldSet iteration ? But I think you get the idea. BUT ! I do not know if this triggers a re-render every time you update the form, maybe it is a bad idea with a large set of inputs ? Let me know what you think. Regarding the checked or unchecked default value, I think of a solution being every time you trigger a checkbox inside your form, call a function which will iterate over every input and look inside input.value to see if every input has the same boolean value, and if so, set the select/unselect checkbox to the corresponding one. |
Beta Was this translation helpful? Give feedback.
You can decide whether the select all checkbox should be checked based the value of the form / fields through
form.value
/fields.permissions.value
etc. To update multiple checkbox at once, you can consider usingform.update()
at the permissions level instead of individual checkbox, e.g.