Skip to content

Instantly share code, notes, and snippets.

@Jhony0311
Created December 15, 2014 17:15
Show Gist options
  • Save Jhony0311/c4655a41d810ff0fd670 to your computer and use it in GitHub Desktop.
Save Jhony0311/c4655a41d810ff0fd670 to your computer and use it in GitHub Desktop.
Dynamic Select for Years Handlebars Helper
Handlebars.registerHelper('eachYear', function(options) {
var data = '';
var d = new Date(); // Get user current date
var year = d.year; // Get year from date created;
for(var x = 1922; x <= year; x++) {
data = data + '<option value="' + x + '">' + x + '</option>';
}
return data;
});
<select id="year" autocomplete="off" class="noblankspace selectPosition dropArrow" type="text" placeholder="Year">
<option value="null">Year</option>
{{!-- Helper implementation without context / Can add context to helper and template if you want --}}
{{#eachYear}}{{/eachYear}}
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment