J.BizMai
J.BizMai

Reputation: 2787

how to serializeArray() with name for array

I have this HTML code :

<input type="checkbox" name="search-form[filters][category][12]" value="cat-12" autocomplete="off" checked="checked" />
<input type="checkbox" name="search-form[filters][category][14]" value="cat-14" autocomplete="off" checked="checked" />

When I´m using the jQuery function serializeArray() like this :

var $postForm = $("#myForm");
console.dir( $postForm.serializeArray() );

I got this :

[
  {
    "name": "search-form[filters][category][12]",
    "value": "cat-12"
  },
  {
    "name": "search-form[filters][category][14]",
    "value": "cat-14"
  }
]

How can I get this :

[
    {
      "search-form"{
             "filters" : {
                   "category" : {
                            "12" : { "value" : "cat-12" },
                            "14" : { "value" : "cat-14" }
                    }
              }  
         }    
    }
]

Upvotes: 0

Views: 64

Answers (1)

y15e
y15e

Reputation: 189

Following git repository may solve your problem.

https://github.com/marioizquierdo/jquery.serializeJSON

Form input, textarea and select tags are supported. Nested attributes and arrays can be specified by using the attr[nested][nested] syntax.

Upvotes: 1

Related Questions