Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Incorrect JSON generation for nested attribute. #16

Open
tusharg1993 opened this issue Aug 19, 2014 · 0 comments
Open

Incorrect JSON generation for nested attribute. #16

tusharg1993 opened this issue Aug 19, 2014 · 0 comments

Comments

@tusharg1993
Copy link

Hey,

I was using your jQuery plugin and have encountered this weird behaviour.

<!DOCTYPE html>
<html>

<head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="jquery.serialize-object.js"></script>
</head>

<body>
    <form id="new_form">
        User Name:
        <input type="text" name="agent_signup[user_name]">
        <br>
        User Email:
        <input type="text" name="agent_signup[user_user_emails_attributes[0][email]]">
        <br>
        Agent Role
        <input type="checkbox" name="agent_signup[role_ids][]" value="1">Account Administrator
        <input type="checkbox" name="agent_signup[role_ids][]" value="2">Administrator
        <input type="checkbox" name="agent_signup[role_ids][]" value="4">Agent
        <input type="checkbox" name="agent_signup[role_ids][]" value="3">Supervisor
        <button>Submit</button>
    </form>
</body>

</html>

To serialize the form, I ran

$("#new_form").serializeObject()

The returned object was

"{"agent_signup":{"user_name":"tushar","user_user_emails_attributes[0":{"email]":"[email protected]"},"role_ids":["1","4"]}}"

whereas the expected object is

"{"agent_signup":{"user_name":"tushar","user_user_emails_attributes":{"0":{"email":"[email protected]"}},"role_ids":["1","4"]}}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant