Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with mixed keys #91

Closed
rafa8626 opened this issue Jul 13, 2016 · 2 comments
Closed

Issue with mixed keys #91

rafa8626 opened this issue Jul 13, 2016 · 2 comments
Labels

Comments

@rafa8626
Copy link

rafa8626 commented Jul 13, 2016

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="[email protected]">
  <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?

@macek macek added the support label Aug 4, 2016
@macek
Copy link
Owner

macek commented Aug 4, 2016

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

  1. cat gets pushed onto user.pets (at index 0)
  2. dog gets pushed onto user.pets (at index 1)
  3. bird gets manually set to users.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="[email protected]">
<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">

@rafa8626
Copy link
Author

rafa8626 commented Aug 4, 2016

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.

@rafa8626 rafa8626 closed this as completed Aug 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants