Skip to content

Incorrect JSON generation for nested attribute. #16

Description

@tusharg1993

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]":"tushar@tushar.com"},"role_ids":["1","4"]}}"

whereas the expected object is

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions