Underlying SELECT not updating

22 views
Skip to first unread message

eagle...@gmail.com

unread,
Apr 17, 2017, 11:46:57 AM4/17/17
to select2
I am just starting to use the select2 script on my site. I have two select inputs on the page so I set up select2 to use a class selector to initialize. Both of the select2 elements are being populated correctly and the visual portion seems to be working fine. However, when I submit my form, only the option that was selected by default is being submitted. When I inspect the page and watch as the various options are selected, I noticed that the underlying <select> element is not being updated at all. Only the original <option> that was selected by default shows the "selected" tag. Do I need to update the "selected" option manually using the :select event? Thanks for any useful feedback that can be provided.

eagle...@gmail.com

unread,
Apr 17, 2017, 7:38:14 PM4/17/17
to select2
On Monday, April 17, 2017 at 11:46:57 AM UTC-4, eagle...@gmail.com wrote:
> I am just starting to use the select2 script on my site. I have two select inputs on the page so I set up select2 to use a class selector to initialize. Both of the select2 elements are being populated correctly and the visual portion seems to be working fine. However, when I submit my form, only the option that was selected by default is being submitted. When I inspect the page and watch as the various options are selected, I noticed that the underlying <select> element is not being updated at all. Only the original <option> that was selected by default shows the "selected" tag. Do I need to update the "selected" option manually using the :select event? Thanks for any useful feedback that can be provided.

Ok, so I'm going to answer my own question in case anyone else runs into the same problem I did. I was using <select> fields with the "multiple" attribute, but I had them named incorrectly. I was naming my field like "tags" when it needed to be "tags[]". This change allowed the form to recognize the multiple selections and pass them all through when the form posted.

Reply all
Reply to author
Forward
0 new messages