/
checkbox-group.bemhtml.js
39 lines (33 loc) · 1.14 KB
/
checkbox-group.bemhtml.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
block('checkbox-group')(
tag()('span'),
attrs()({ role : 'group' }),
js()(true),
mix()([{ block : 'control-group' }]),
content()(function() {
var mods = this.mods,
ctx = this.ctx,
val = ctx.val,
isValDef = typeof val !== 'undefined';
if(isValDef && !Array.isArray(val)) throw Error('checkbox-group: val must be an array');
return (ctx.options || []).map(function(option, i) {
return [
!!i && !mods.type && { tag : 'br' },
{
block : 'checkbox',
mods : {
type : mods.type,
theme : mods.theme,
size : mods.size,
checked : isValDef && val.indexOf(option.val) > -1,
disabled : option.disabled || mods.disabled
},
name : ctx.name,
val : option.val,
text : option.text,
title : option.title,
icon : option.icon
}
];
});
})
);