Last active
July 26, 2016 03:24
-
-
Save themeteorchef/27ae4f4e4617e0057d77 to your computer and use it in GitHub Desktop.
Select item select box that matches the passed value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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