Open marioizquierdo opened 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!
@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.
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.
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.
Yes, the confusion with the checkboxes is actually pretty common. I blame the W3C standard ;)
@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!
Nice, that's a much more elegant approach
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 ;)