macek/jquery-serialize-object

Need a value parser for the object

muthursyamburi opened this issue · 2 comments

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

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.

That worked! Thanks much dear 👍