kartik-v / yii2-widgets

Collection of useful widgets for Yii Framework 2.0
http://demos.krajee.com/widgets
Other
558 stars 175 forks source link

Select2 > When option selected, "selected" tag not added to select option element #319

Closed mmmmmmmkay closed 6 years ago

mmmmmmmkay commented 8 years ago

Hi Kartik,

Awesome widgets, thanks for sharing!!

I had a question about the Select2 widget --

It is my understanding that a typical "select" dropdown works as follows according to HTML standard -- when an option is selected from a dropdown list, a "selected" tag is added to the select option element (like this: http://www.w3schools.com/tags/att_option_selected.asp)

However using the Select2 component, I noticed the option "name" is added as the "title" attribute with "name" as value -- the "select option" element (or multiple elements in the case of a mulitple select) is not updated with the "selected" tag.

1

I want to serialize the form to send the form POST data via an Ajax request but the selected value does not get serialized because it is not in a supported form input element with the "selected" tag. Can you tell me if there is a way to add the "selected" tag to "select option" element?

Thanks!

kartik-v commented 6 years ago

It does not update the DOM the way you mentioned.

However you can get the value selected by this simple jQuery function:

$('#select-input-id').val();