Create a gist now

Instantly share code, notes, and snippets.

@acidsound / Secret
Last active Aug 29, 2015

What would you like to do?
"select" HandleBars Helpers can set selected/checked attributes for Radio and Select.
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"
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;

acidsound commented Mar 10, 2014

usage1. radio

          {{#select specialistType}}
          {{#each codes "establishment"}}
            <input type="radio" value="{{code}}"/>

acidsound commented Mar 10, 2014

usage2. select

          <select name="PH" id="PH">
          {{#select PH}}
          {{#each codes "PH"}}
            <option value="{{code}}">{{name}}</option>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment