nope… this is not a solution, because you need to prepare full logic to each Preference field of that type, and check for change… and, of course, when you have separated forms for this kind of prefrences, like on screenshot, you probably “disable” or will change something what you wont change at all.
maybe i’m not good on explaining things, but… how you exactly wish solving this kind of behaviour? there are 2 main issues…
1st problem
When unchecked item is not sent you are not aware to change that value, from true to false. right? then you are not able to switch something, only if it is as radio buttons with direct values of true/false…
2nd problem
if you wish to use this kind of settings/prefrencies, you need to know exact list of prefrencies to be checked for in preprocessing (beforeSave) event, or something. right? only then you are able to correctly set “false” values on booleans
3rd problem
as i mentoined before, when you splited multiple inputs for UserPrefrence, then you need to be aware of each one for each form to update only correct properties. for now, there are no funcionality to list all user preferencies which was created/stored, you need to call each one by one, then when you wish to create some funcionality on beforeSave, then you probably need sent a list of properties to be checked or something…
“solution” (minimum effort)
if you wish to use UserPreference as a boolean with checkboxes / switches, you need to create a specific funcionality like i wrote before.
<input type="checkbox" onchange="correctValue(this,'#stop')" id="check1">
<label for="check1">Stop all questions...</label>
<input type="hidden" name="Preference[stop_annoying_questions]" id="stop">
and… of course… some javascript to fill value to “#stop” - hidden input…
function correctValue(el, target) {
document.querySelector(target).value = el.checked ? true : false;
}
example pen > https://codepen.io/snipiba/pen/XWLWPKM (hidden field is rendered as text to see if correct value is set properly.
solution with effor as faaaaak
- create hidden field with comma separated list of properties to be used on loop in beforeSave method.
- create beforeSave method on model to check if there are some input field (for now call it
_prefrencies
) …
- loop all provided
_preferencies
to check if is posted, if exists, and then correctly update value to false when is bool value, etc.
tell me, who will go this way?