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

74 lines
1.2 KiB
JavaScript

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:
{
type: RadioGroup
,set: function (x)
{
this.link ({_radioGroup: x}, {changed: this._onRadioGroupChange});
this.node.name = x.radioName
this._onRadioGroupChange ();
}
,get: function ()
{
return this._radioGroup;
}
}
}
,_radioGroup: null
,render: function ()
{
var radio = this.doc.createElement ('input');
radio.type = 'radio';
radio.name = '';
radio.checked = false;
radio.addEventListener ('change', this._onChange.bind (this));
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;
}
});