brainfoolong / form-data-json

A zero dependency, cross browser library to easily get or set/manipulate form input values as/from a json object.
https://brainfoolong.github.io/form-data-json
MIT License
57 stars 10 forks source link

FR: The way to assign `false` values for unchecked checkboxes #12

Closed KES777 closed 2 years ago

KES777 commented 2 years ago

Is your feature request related to a problem? Please describe. https://github.com/marioizquierdo/jquery.serializeJSON#include-unchecked-checkboxes Idea of data-unchecked-value is interesting:

<input type="checkbox" name="checked[b]"   value="true" data-unchecked-value="false" checked/>

Also I like the idea to ignore empty fields: https://github.com/marioizquierdo/jquery.serializeJSON#ignore-empty-form-fields

brainfoolong commented 2 years ago

Thanks for that ideas. I know this jquery plugin, as i've used it before i've created this library. But, i am not a fan of any data-* property annotations to modify the behaviour of this library. So i must decline that.

The other thing with empty fields, this could already be done with the "inputFilter" option. The idea was to create a generic filter option to allow the user to do everything. Creating "aliases/shorthand" functions/helpers for existing features is not a thing i tend to do in my libraries. It just boils up the codebase with no real advantage other than making calls "shorter".

brainfoolong commented 2 years ago

But to the empty fields, maybe this could be a thing, as there are already similar options like includeDisabled. I think about that.

KES777 commented 2 years ago

modify the behavior of this library

So I should write some extra code to reprocess resulting hash. ok ;-)

Actually any library is a short cut for some task. So it is OK if library ship with it frequently used tools. So developers will not reinvent the wheel.

I agree with your notice that includeDisabled is shorthand for core inputFilter feature. And this is cool when developer could just say: I want to use this, that or those filters.

Thank you.

brainfoolong commented 2 years ago

Actually any library is a short cut for some task.

Yep, that's true.

As a library maintainer, it's sometimes hard to make decisions that satisfy all needs equally. Every developer has ideas how things should or can be done. Many of them are personal preference, for sure. I love to hear about that ideas and discus them, as we currently do hear.

Thanks for that feedback.

brainfoolong commented 2 years ago

A new pre-release does exist. https://github.com/brainfoolong/form-data-json/releases from branch https://github.com/brainfoolong/form-data-json/tree/v2-dev - Maybe you give it a shot. I took your feedback into consideration and refactored the hole thing as it has a few flaws that i didn't liked.