Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Old trick doesn't work #9

Closed
kud opened this issue Mar 28, 2014 · 5 comments
Closed

Old trick doesn't work #9

kud opened this issue Mar 28, 2014 · 5 comments

Comments

@kud
Copy link

kud commented Mar 28, 2014

Hello,

Be warned, the old trick where you have:

<input name="cgv" value="false" autocomplete="off" type="hidden">
<input name="cgv" value="true" autocomplete="off" type="checkbox">

doesn't work anymore, because it makes an array.

I find this solution:

formData = $form.serializeObject()
if ( typeof formData.cgv === 'undefined' ) formData.cgv = false

but maybe it could be good to have data-attr to handle that.

@hongymagic
Copy link
Owner

What trickery is that?

@kud
Copy link
Author

kud commented May 25, 2014

On a classic form (without javascript), if the backend always wants a datum about a certain name (mostly on radio or checkbox), you have to make a trick which consists of doing your normal input:

<input name="cgv" value="true" autocomplete="off" type="checkbox">

plus another hidden input just above in case where the user doesn't check the input.

<input name="cgv" value="false" autocomplete="off" type="hidden">

In this way, if the input[type=text] isn't checked, it's the input[type=hidden] which is sent. If it's checked, it's the input[type=text] overrides the name and it's it which is sent.

The thing is with your plugin, this trick doesn't work; because it doesn't override but it makes an array for this name.

@hongymagic
Copy link
Owner

@kud I see.

This plugin is a mere transformation of $.serializeArray. I understand that this could be an issue, however I don't intend on addressing a fix for this trick. The output of this plugin should be consistent to $.serializeArray.

I will leave this open until README is updated to reflect this behaviour.

Thanks for letting me know!

@kud
Copy link
Author

kud commented Dec 9, 2014

Okay thank you @hongymagic for having taken the time to answer me. ;)

@hongymagic
Copy link
Owner

Now on README

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants