marioizquierdo / jquery.serializeJSON

Serialize an HTML Form to a JavaScript Object, supporting nested attributes and arrays.
MIT License
1.71k stars 433 forks source link

Option for include parsed 0 values #101

Closed MartinNovak83 closed 4 years ago

MartinNovak83 commented 4 years ago

First of all, thank you for your great plugin.

I have only one issue - with parseNumbers: true, elements with value="0" are ignored, because are treated like falsy. This is somethink I don't want. For some reason I need elements with 0 in json result. So there should be some option to achieve this. Or did I overlook some existing settings? I tried to play with skipFalsy... options but without success.

marioizquierdo commented 4 years ago

The value "0" should be parsed just like any other value. See the example in our unit tests: https://github.com/marioizquierdo/jquery.serializeJSON/blob/master/spec/spec.js#L711

Maybe there's something else going on? maybe some other plugin, or the jQuery selector you are using is not including that input. Or maybe you are using a checkbox? Checkboxes in HTML forms are ignored if they are unchecked. If this is a checkbox, try setting the attribute data-unchecked-value="0" so it is included when unchecked.

Could you provide more details of your use case?