-
-
Save acidsound/a7de8f12acafc787dff2 to your computer and use it in GitHub Desktop.
"select" HandleBars Helpers can set selected/checked attributes for Radio and Select.
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
Handlebars.registerHelper "select", (value, options) -> | |
select = document.createElement("div") | |
$(select).html options().replace(/<[/]*\$data:\w+>/g, "") | |
$("input[type=radio]", select).filter("[value='#{value}']").attr "checked", "checked" | |
$("option", select).filter("[value='#{value}']").attr "selected", "selected" | |
select.innerHTML |
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
Handlebars.registerHelper("select", function(value, options) { | |
var html, select; | |
select = document.createElement("div"); | |
$(select).html(options().replace(/<[/]*\$data:\w+>/g, "")); | |
$("input[type=radio]", select).filter("[value='" + value + "']").attr('checked', 'checked'); | |
$("option", select).filter("[value='" + value + "']").attr('selected', 'selected'); | |
return select.innerHTML; | |
}); |
usage2. select
<select name="PH" id="PH">
{{#select PH}}
{{#each codes "PH"}}
<option value="{{code}}">{{name}}</option>
{{/each}}
{{/select}}
</select>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage1. radio