Skip to content

bootstrap_form_tag and collection_select giving bad name #193

@burnt43

Description

@burnt43

Hello, I have a form that isn't associated with an object and therefore I am using bootstrap_form_tag. On this form I have a button where I can add different search filters which will add an an additional dropdown box when clicked. This means I can have an indefinite amount of dropdowns. My code abbreviated looks like the following:

= bootstrap_form_tag(bsf_opts(url: "/recorded_calls", method: :post)) do |f|
...
  %td= f.collection_select "durations_greater_less[]", @duration_options, :last, :first, hide_label: true

The html that the f.collection_select generates is found and cloned and added to the page with jQuery when the user clicks a button to add a new filter. The problem is the html that is generated has what I think is an incorrect name. Below is the html that comes out. the name is "[durations_greater_less[]]". This is a problem because lets says a user makes 5 of these dropdowns, I expect to receive as params an array for durations_greater_less, but since the name is enclosed with "[]" the params is not an array, it is a single value. I expect the name to be just durations_greater_less[].

<select class=form-control name=[durations_greater_less[]] id=_durations_greater_less[]>
  <option value=gt>Greater Than</option>
  <option value=lt>Less Than</option>
</select>

I tried to trace this out in the code, but I got stuck in the form_group method on form_builder.rb on the line

control = capture(&block).to_s

I see that capture is delegated to @template, but I do not know where @template comes from. Before the aforementioned line I did capture(1,2) just so it would raise an exception that I had the wrong number of args. In the backtrace I saw capture was going to code in another gem, so I'm not sure if it is the other gem where the issue lies or maybe there is just some data in bootstrap-forms I need to change to get this working.

In the meantime I can hack a solution with using rails select_tag and I'll set the classes manually to have it bootstrap styled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions