rails/request.js

Multiselect is only sending the last selected option

luismoyano opened this issue · 5 comments

Hello!

Having a form with a multiselect where all the options are selected, only the last one is sent to the server.

How to reproduce:

  • Have a form with a multiselect
  • Add two or more options to it
  • On a JS file pick that form using FormData
  • Create a new request object with new FetchRequest('get', 'a/url', {contentType: 'application/json', responseKind: 'json', data: yourFormData})
  • Call the query method with yourFetchRequest.query
  • Notice the url params only include the last item in the multiselect

This happens on utils.js on the merge entries method: The entries for a multiselect have identical keys looking similar to my_model[my_multi_field][] and different values which are deleted and replaced for the last one.

I think this PR fixed that #50

Ah yes! I can see it now, I'm using request.js from npm directly, is there any chance to update it there or do I need to use the gem? (I'd rather not to)

@luismoyano you saying you have defined request.js as a dependency on your package.json file? If so, you can just change the following

"@rails/request.js": "^0.0.6",

to

"@rails/request.js": "https://github.com/rails/request.js.git#main",

That will use what is available on main.

can you test and see if it works? I'll close the issue, but let me know if the problem persists and we can work on a fix