brainfoolong / form-data-json

A zero dependency, cross browser library to easily get or set/manipulate form input values as/from a json object.
https://brainfoolong.github.io/form-data-json
MIT License
60 stars 10 forks source link

Array is expected #10

Closed KES777 closed 3 years ago

KES777 commented 3 years ago

Describe the bug I expect array for multiple values, but hash is returned

To Reproduce

<form>
    <input name = "docn">
    <input name = "docdate">

    <input name = "client[name]">
    <input name = "client[edrpou]">

    <input name = "client[phone][]">
    <input name = "client[phone][]">
    <input name = "client[phone][]">

    <input name = "client[email][]">
    <input name = "client[email][]">

    <select name="client[status][]" id="cars" multiple>
      <option value="volvo">Volvo</option>
      <option value="saab">Saab</option>
      <option value="opel">Opel</option>
      <option value="audi">Audi</option>
    </select>

    <input type="checkbox" name="scales[]" checked value="77">
    <input type="checkbox" name="scales[]">
</form>
FormDataJson.fillFormFromJsonValues($("form")[0], 
  {docn : 'asdf', docdate: 'addd', client: { name: 'asdf DDD', phone: [ 'zzzz', 'dd' ] } }, 
  new FormDataJsonOptions({ unsetAllInputsOnFill: true }) 
)

image

brainfoolong commented 3 years ago

Thanks for the bug report. I can confirm that there is currently no array return for numeric indexed objects, that should obviously be an array. I will fix this.

brainfoolong commented 3 years ago

Ah, this may take a while longer as expected to fix this. It's easy to fix them in the first place, but it does not incorparate with the counterpart (fillFromJson and toJson) well, because this internal process does handle some things very special when a real array is passed. I have to refactor that a bit and do some more tests with this.

brainfoolong commented 3 years ago

This error should be fixed in the new pre-release.

KES777 commented 3 years ago

fixed