macek / jquery-serialize-object

Converts HTML form into JavaScript object
Other
1.11k stars 352 forks source link

Need a value parser for the object #82

Closed muthursyamburi closed 8 years ago

muthursyamburi commented 8 years ago

Hi,

This is an awesome tool which really made my life way much easier. However I was looking for an additional feature.

I wanted to parse the values before writing them to the Java/JSON objects.

eg:

<select name="YourOptions" id="opt1">
     <option>Your Choice is: 1</option>
     <option>Your Choice is: 2</option>
     <option>Your Choice is: 3</option>
     <option>Your Choice is: 4</option>
</select>

And when the user selects an option, say the 3rd one which is: "Your Choice is: 3", as of now it gives:

{YourOptions : "Your Choice is: 3"}

But I want it to be like this:

{YourOptions : "3"}

Is there a way to extend the validations for parsing the values?

macek commented 8 years ago

You'll be pleased to know you can easily solve this problem.

Make sure to include a value attribute with your option tags. Like this:

<option value="1">Your Choice is: 1</option>
<option value="2">Your Choice is: 2</option>
<option value="3">Your Choice is: 3</option>
<option value="4">Your Choice is: 4</option>

Let me know if you have any other issues.

muthursyamburi commented 8 years ago

That worked! Thanks much dear :+1: