0
1
Fork 0
hedera-web-mindshore/js/htk/field/radio.js

76 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-09-26 09:28:47 +00:00
var RadioGroup = require ('./radio-group');
module.exports = new Class
({
Extends: Htk.Field
,Tag: 'htk-radio'
,Properties:
{
tip:
{
type: String
,set: function (x)
{
if (x)
this.node.title = _(x);
}
},
radioGroup:
{
2016-09-26 09:28:47 +00:00
type: RadioGroup
,set: function (x)
{
if (this._radioGroup)
this._radioGroup.removeButton (this);
this.link ({_radioGroup: x}, {'changed': this._onRadioGroupChange});
this.node.name = x.name;
x.buttons.push(this);
this._onRadioGroupChange ();
}
,get: function ()
{
return this._radioGroup;
}
}
}
,_radioGroup: null
2016-10-16 14:16:08 +00:00
,render: function ()
{
2016-10-16 14:16:08 +00:00
var radio = Vn.Browser.createRadio ('', this.doc);
radio.checked = false;
radio.addEventListener ('change', this._onChange.bind (this));
2016-10-14 10:58:35 +00:00
this._node = radio;
}
,_onChange: function ()
{
if (this.node.checked && this._radioGroup)
this._radioGroup.value = this.value;
}
,_onRadioGroupChange: function ()
{
if (this._radioGroup.value && this._radioGroup.value == this.value)
this.node.checked = true;
else
this.node.checked = false;
}
,putValue: function (value)
{
if (!value)
this.node.value = '';
else
this.node.value = value;
}
,setEditable: function (editable)
{
this.node.disabled = !editable;
}
});