Issue with mixed keys
rafa8626 opened this issue · 2 comments
Based on #18 I was able to override fixed using $.extend(FormSerializer.patterns, {...})
by setting fixed: /^$/
The problem is that I have a case like this:
<form id="contact">
<input name="user[email]" value="jsmith@example.com">
<input name="user[pets][]" type="checkbox" value="cat" checked>
<input name="user[pets][]" type="checkbox" value="dog" checked>
<input name="user[pets][]" type="checkbox" value="bird">
<input name="user[pets][7]" type="checkbox" value="tiger" checked>
<input name="user[pets][182]" type="checkbox" value="bull" checked>
<input name="user[pets][19999]" type="checkbox" value="chicken">
<input type="submit">
</form>
So that thing solves the issue #18 but it's not grabbing the ones that don't have a number between [], any advises on how to achieve this?
Well your situation is sort of broken, at least as I see it here
What is 7
, 182
, and 19999
? What is their significance?
How do you see the following form working?
<input name="user[pets][]" type="checkbox" value="cat" checked>
<input name="user[pets][]" type="checkbox" value="dog" checked>
<input name="user[pets][1]" type="checkbox" value="bird" checked>
The bird
would overwrite the dog
value because
cat
gets pushed ontouser.pets
(at index0
)dog
gets pushed ontouser.pets
(at index1
)bird
gets manually set tousers.pets[1]
, overwriting the existing value,dog
I can see that in your static example, there is no collision of indexes, but I'm guessing those indexes (7
, 182
, and 19999
) are determined by dynamic values of some kind.
Without knowing more about your specific situation, my only recommendation would be to just us a manual index
<input name="user[email]" value="jsmith@example.com">
<input name="user[pets][0]" type="checkbox" value="cat" checked>
<input name="user[pets][1]" type="checkbox" value="dog" checked>
<input name="user[pets][2]" type="checkbox" value="bird">
<input name="user[pets][7]" type="checkbox" value="tiger" checked>
<input name="user[pets][182]" type="checkbox" value="bull" checked>
<input name="user[pets][19999]" type="checkbox" value="chicken">
These are IDs from the database, but the user adds new elements and we keep the array element open. Well I'll try to check with my team about this. Thanks.