Giter Club home page Giter Club logo

Comments (2)

macek avatar macek commented on September 16, 2024

When it comes to creating arrays of objects that have more than one field, you
have no other choice but to specify the array indexes for the objects that the
fields belong to.

Hopefully a simple demonstration makes that explantion a little more clear

<input name="hello[0][a]" value="1">
<input name="hello[0][b]" value="2">

Output

{
    hello: [ {a: 1, b: 2} ]
}

If we don't specify the 0 index, watch what happens

<input name="hello[][a]" value="1">
<input name="hello[][b]" value="2">

Output

{
    hello : [ {a: 1}, {b: 2} ]
}

Notice we have 2 objects created in the array instead of the desired 1.


Now let's take a look at how we'd format the fields for your entire form to get
the object you're looking for

<input name="character[0][male]">
<input name="character[0][female]">
<input name="character[0][result]">

<input name="character[0][itinerary][0][activity]">
<input name="character[0][itinerary][0][lat]">
<input name="character[0][itinerary][0][long]">

<input name="character[0][itinerary][1][activity]">
<input name="character[0][itinerary][1][lat]">
<input name="character[0][itinerary][1][long]">

<input name="character[0][itinerary][2][activity]">
<input name="character[0][itinerary][2][lat]">
<input name="character[0][itinerary][2][long]">

Now you're much closer to the object you're looking for.

However, I notice you're looking for string and number serialization. This
is not possible with the current version of jquery-serialize-object.

I'm currently working on getting the plugin up to spec of the W3C Draft
Specification for HTML JSON form submissions
. After this is implemented,
jquery-serialize-plugin will take the type of your <input> elements into
account.

Serialize strings

<input type="text">

Serialize numbers

<input type="number">

Serialize boolean

<input type="checkbox">

If you have any more questions about this, let me know and I'll try to help.

from jquery-serialize-object.

macek avatar macek commented on September 16, 2024

Closing this issue. If you have other questions, we can always re-open it.

from jquery-serialize-object.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.