Comments (4)
Hi. I cannot find an error here, can you post what your expected result should be? The object you've posted show exactly the values and names of your given input examples.
from form-data-json.
If I use fields with name index in 'correct' order like this:
<input type="hidden" name="Company[Phone][0][id]" value="122" class="form-control" />
<input type="hidden" name="Company[Phone][0][phone]" value="3339991111" class="form-control" />
<input type="hidden" name="Company[Phone][1][id]" value="125" class="form-control" />
<input type="hidden" name="Company[Phone][1][phone]" value="33" class="form-control" />
I have got the result:
Phone => [
{
id => 122,
phone => 3339991111,
},{
id => 125,
phone => 33,
},
],
At first example I receive hash of hashes. At this example I have array of hashes.
from form-data-json.
Hi, this is exactly what should happen. This library does create data out of input names, and when your input names are not "in order", it must create an object instead of a real array, because arrays cannot have "gaps" in the index numbers.
This library does not check or "assume" that the gap should be ignored and make an array out of it. It doesn't matter if the keys are numbered or have any other arbitrary value, it will be an object (hash you call it).
Real arrays only, and really only, can be produced when you have keys starting with zero and with no gaps in between. 0,1,2,3,4
is ok, 0,1,3,4,5
isn't.
You have to create correct names of inputs if you really want an array instead of an object.
It is no bug nor a feature that is supported by this library. It boils basically down to a previous feature request of you, manipulating data before/after the output. You have to do it your own way, when your data/input names is different to the things you need.
Btw. - Working without any key name []
will also not work here, as every empty key []
will increase index number in the result, which is also expected.
from form-data-json.
Thank You very much!
from form-data-json.
Related Issues (20)
- v2-dev: `skipEmpty` still includes empty arrays/objects HOT 12
- Document how to import this module HOT 18
- IncludeButtonValues does not include button values HOT 4
- Trigger for 'onchange' HOT 2
- Doesn't work when inputs are nested more than one child element deep HOT 1
- Focus Element metod HOT 1
- Implement FormDataGraphQL HOT 3
- Automatic array processing while fromJson HOT 2
- Get empty value in the data if use field name with nesting (array) HOT 4
- Name syntax with dot HOT 2
- Conversion of a list of element[number] not done when a number is missing HOT 3
- radio element value 0 HOT 1
- how to skip non selected select option HOT 2
- Module parse failed: Unexpected token (15:30) HOT 4
- Use `import` instead of `require` HOT 3
- Wouldn't it be nicer if toJSON returns promise HOT 1
- Selection of checkboxes should based on values instead of order in DOM HOT 7
- Typing of typescript Suggestion HOT 2
- Proposal to Improve the Manipulation of Masked Field Values in Forms HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from form-data-json.