Skip to content

Instantly share code, notes, and snippets.

@themeteorchef
Last active July 26, 2016 03:24
Show Gist options
  • Save themeteorchef/27ae4f4e4617e0057d77 to your computer and use it in GitHub Desktop.
Save themeteorchef/27ae4f4e4617e0057d77 to your computer and use it in GitHub Desktop.
Select item select box that matches the passed value.
<template name="example">
<select class="form-control" name="select">
{{#each teams}}
<!--
Here, ../team (../ is a Handlebars convention for traversing template scope) allows us to get the team
value from the parent template (i.e. {{team}}). this._id allows us to get the _id value of the current
item being iterated, or in this example, the _id of the current team. Our UI helper matches the current
team against the current option, if they match, that option is displayed as selected in the select box.
-->
<option {{selectOption ../team this._id}} value="{{_id}}">{{name}}</option>
{{/each}}
</select>
</template>
# Select Option
# Marks an option in a select as selected if the option and value match.
UI.registerHelper 'selectOption', (option,value)->
if option == value then 'selected' else ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment