Turbo Frame Advance Form submission problem

Hi,

Bit of a weird scenario here. I have a form with multiple inputs, when an input is changed, a Stimulus controller triggers “.requestSubmit()” on the form. The form has the following data attributes on it:

turbo_frame: “object-listing”, turbo_action: “advance”

This makes sure that the object-listing frame gets updates with the results of the form submission and the advance attribute updates the URL and places, as a query string, the filled in form fields.

It all basically works as a filter system to filter items in a grid below.

I’ve hit an issue where I have a filter input in the form of a select field, in this case a multiple one. When the URL gets advanced, the URL parameters look like the following:

?sort=order&attributes=Tilt&attributes=Brakes

Obviously, in my Rails controller when I am checking if the attributes parameter exists, I only end up with Brakes and I don’t see Tilt. Ideally, I’d like each option selected in the multi-select to show up in a concatenated form such as:

?sort=order&attributes=Tilt|Brakes

Then the parameter would be Tilt|Brakesand I can easily split on the | character and grab what I need from the database.

I have tried modifying the FormData object before .requestSubmit() is called. I can get this output, BUT, on submission, the URL still shows the original format and hence the filter fails.

Any suggestions?

I believe you want the param to indicate it’s an array.

<select name=“attributes[]”…

Which creates the GET URL ?sort=order&attributes[]=Tilt&attributes[]=Brakes

Does this appear in Ruby as an array then? I tried this previously but because the URL query string contained attributes twice, I didn’t actually check what appeared in the params hash at the controller end.

I’ve actually managed to hack toegther a workaround.

I manipulate the FormData when the multi-select is changed, to concatenate the items together, but as I can’t put that FormData back into the form, I set the value of a hidden text input to that new string and then disable the multi-select while the form submission is done (this makes sure the select field doesn’t show in the URL).

It’s clunky but does appear to work. I have commented it well so I will understand when i look back at the code.

Does this appear in Ruby as an array then?

Correct