user687554
user687554

Reputation: 11151

Unable to pre-select select value

I have a web page with a drop down list. I have a JSFiddle of my problem here. The drop-down list is rendered with the select2 plugin. I need to support tags in the drop-down list. My drop-down list works fine during the initial (create) state). However, when I am editing a record, I cannot figure out how to pre-populate the selected value. I tried following the example from the docs which had the following:

$('#NameDisplay').select2({
  tags: ["Randy"]
}); 

However, as my Fiddle shows, it doesn't work. I included a "Basic" drop-down just to try to get something to populate. I also included a "Complete" to better show my entire scenario. I can't figure out what I'm doing wrong.

Upvotes: 1

Views: 62

Answers (1)

John S
John S

Reputation: 21492

You can just set the value attribute of the <input> element. Set it to a comma-separated list of the tags.

<input class="form-control input-sm" id="NameDisplay"
       name="NameDisplay" type="text" value="Randy" />

Upvotes: 1

Related Questions