How can you correctly pre-populate a select control with the current value from the template?
I have a simple form to edit a record where the values for the selected record are pre-populated when the form is shown. A bit like this:
<input type="text" id="project_name_edit" value="{{selected_name}}">
But where I am using a select control I need to be able to interogate the template value and conditionally set the selected='selected' property for the correct option.
<select id="project_status_edit" value="{{selected_status}}">
<option>GOOD</option>
<option>BAD</option>
<option>UGLY</option>
</select>
handlesbars.js offers the #IF helper but this only gives truthy or falsy.
I could probably hack this in various way but this seems like a scenario where there would be a standard solution.
You can use a helper:
Which you can then call with:
Using:
Try it here:
http://tryhandlebarsjs.com/
Although it doesn’t appear to let me save it.
:(