Pavarine
Pavarine

Reputation: 726

Meteor.js Load Persisted Option in Select Box

I have a Plataforms collection in MongoDB, and a form in which I can persist new Projects ( one project have one plataform ), and the options are generated in a html select like this:

{{#each plataforms}}
    <option>{{name}}</option>
{{/each}}

Which gives me a html select where I choose one option and click "save button". That works fine and I can persist the selected option by name ( value = option text ).

My problem is when I want to edit my "Project". I can load all the persisted data which are single text inputs, but I cant load the previous persisted option in the select. It always gives me the first option of the select input, and not the previous persisted selected option.

How can I achieve this? Sorry for bad english.

Upvotes: 0

Views: 169

Answers (2)

Lumi Lu
Lumi Lu

Reputation: 3305

Try something like this,

$('#mySelect option[value="somevalue"]').prop('selected', 'selected');

Upvotes: 1

Ian Jones
Ian Jones

Reputation: 1509

You need to set selected on the 'persisted' option:

<option selected="selected">

Upvotes: 0

Related Questions