maxatwork / form2js

Javascript library for collecting form data
http://maxatwork.github.com/form2js/
MIT License
640 stars 137 forks source link

Same as https://github.com/marioizquierdo/jquery.serializeJSON #61

Open marioizquierdo opened 10 years ago

marioizquierdo commented 10 years ago

I know this is not an issue but I didn't know how to send you a message.

I noticed that this library solves exactly the same problem I solved on my jquery.serializeJSON plugin.

I am also surprised that we both decided to format the fields as in Rails.

I will add a reference to this repository from my README file as the "no jQuery" solution ;)

yairEO commented 10 years ago

since you have 0 issues in your project Github and this form2js one has 40..I will use serializeJSON. make so sense using a neglected code. thanks for posting this!

endeavor85 commented 10 years ago

@marioizquierdo your jquery.serializeJSON plugin works extremely well and is well documented but lacks a few features offered by form2js. Namely, for my typical usage, the getDisabled option and the handling of checkboxes. In your documentation you show a workaround for checkboxes, but since 985a3f3214 such a workaround is not necessary with form2js.

marioizquierdo commented 10 years ago

I don't have plans to support such a feature. jquery.serializeJSON is built on top of jquery.serializeArray, which is one of the reasons why the code is so stable. The .serializeArray() method uses the standard W3C rules for successful controls, to determine which elements it should include; in particular the element cannot be disabled and must contain a name attribute. The idea is to be as W3C compliant as possible, even if it requires creating some common "gotchas". At least they are the same gotchas as any other web form.

endeavor85 commented 10 years ago

Understood. So it would seem the usage scenarios are a bit different then. This project may deviate from W3C compliance in order to satisfy various (perhaps non-standard) requirements. Nonetheless, I appreciate your contribution as it seems to solve its problem.

marioizquierdo commented 10 years ago

Yes, the confusion with the checkboxes is actually pretty common. I blame the W3C standard ;)

marioizquierdo commented 10 years ago

@endeavor85 I was thinking a little more about how common is the checkbox problem and I came up with a solution that is not obtrusive.

By default, serializeJSON still does not include unchecked checkboxes, but from version 2.2.0, the attribute data-unchecked-value can be used to make it work without hidden fields:

<input type="checkbox" name="show" value="true" data-unchecked-value="false">

Also, the new option checkboxUncheckedValue could be used to use a default value for all unchecked checkboxes without having to repeat the data-unchecked-value over and over again in the HTML.

Thank you for your feedback!

endeavor85 commented 10 years ago

Nice, that's a much more elegant approach