Skip to content

Instantly share code, notes, and snippets.

@awinogradov
Last active August 29, 2015 14:02
Show Gist options
  • Save awinogradov/090af0ebd0d4c58bee60 to your computer and use it in GitHub Desktop.
Save awinogradov/090af0ebd0d4c58bee60 to your computer and use it in GitHub Desktop.
Select on BEMHTML
{
block: 'input',
mods: {type: 'select'},
options: [
{
name: 'one',
val: 1
},
{
name: 'two',
val: 2
}
]
}
block('input').mod('type', 'select')(
content()(function() {
var options = [], ctx = this.ctx, content;
if (ctx.options) {
options = ctx.options.map(function (item) {
return {
block : 'input',
elem : 'option',
attrs : {value: item.val},
tag : 'option',
content : item.name
}
});
options[0].attrs.selected = 'selected';
content = [
{ elem : 'control', tag : 'select', content : options }
];
}
else {
content = [{ elem: 'control', tag: 'select', content: ctx.content }];
}
ctx.label && content.unshift({ elem: 'label', content: ctx.label });
return content;
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment