-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checkbox reader behavior is inconvenient for some possible uses. #85
Comments
Thanks for the feedback @poifox ! PRs are welcome if you're keen, otherwise this will go on the queue |
Hi @rhubarbselleven, thanks for getting back to me on this. I'll see if I can do the change myself but I don't promise anything, if I was able to do this, what branch should I merge into, |
Hi @poifox, yes minor would be fab |
While rummaging through the source code I actually understood how // Let's customize the checkbox recollection behavior first.
// This collects the value from the checkbox
Backbone.Syphon.InputReaders.register('checkbox', function(el) {
return el.val();
});
// And this makes sure that the value gets collected only for checked inputs
Backbone.Syphon.KeyAssignmentValidators.register('checkbox', function($el, key, value) {
if ($el.prop("checked")) {
return true;
}
return false;
});
// [Marionette view here...] It was a good experience to look at the source code and realize that all I needed was in there, I just needed to learn how to use it. Maybe this example could be used in the documentation for future reference? Anyway, I think the issue can be closed now. Cheers! |
Thanks for the update @poifox ! I'll link this one to #24 as this is something I'd like to see resolved when we're ready to do a code breaking release. |
I've been using Syphon while learning Marionette and I'm absolutely loving it. Recently I started using it for a production setup to collect a post's data before saving it and one of the model fields is an array of category IDs.
I have something like this for that particular field:
I saw the documentation for changing the behavior for checkbox value collecting and so I modified the input reader for checkboxes like so:
But I've found this is still adding an
undefined
value when a checkbox is not checked; for example if I select just the last two categories I get something like thiswhich I'm forced to clean after
Backbone.Syphon.serialize(this)
with a quick loop.It would be cool to have a way to get only the actual values and not the undefined ones, as in
if the value returned is null or undefined, don't add it to the data
, unless there are implementation or other reasons behind not doing this.Anyway, thanks a lot for your time and awesome libs.
The text was updated successfully, but these errors were encountered: