Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty array value being input with simple_form entries

I'm still new to rails and simple_form and have been trying to implement a multiple select option to give a user multiple roles.

Current input looks like this

<%= f.input :secondary_role, :collection => UseridRole::VALUES, :include_blank => false,:label => "Secondary Role(s):", :input_html => {  :class => " simple_form_bgcolour simple_form_position overide_selection_field_width", :size => 4, multiple: true } %>

So, this does work, but is including an empty value at the start of my array:

"secondary_role" : [
        "",
        "admin"
    ]

I have the same code above which works for my primary_role value which is a string, but my secondary_role can have multiple values so is stored as an array.

Where should I be looking to fix this issue?

like image 664
s89_ Avatar asked Sep 08 '26 05:09

s89_


1 Answers

It seems like Rails is adding a hidden field to the collection. Try adding include_hidden: false to your form input.

like image 115
Mark Merritt Avatar answered Sep 11 '26 10:09

Mark Merritt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!