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

74 lines
1.2 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)
{
2017-04-19 06:16:37 +00:00
this.link ({_radioGroup: x}, {changed: this._onRadioGroupChange});
2017-04-08 11:42:27 +00:00
this.node.name = x.radioName
this._onRadioGroupChange ();
}
,get: function ()
{
return this._radioGroup;
}
}
}
,_radioGroup: null
2016-10-16 14:16:08 +00:00
,render: function ()
{
2017-04-08 11:42:27 +00:00
var radio = this.doc.createElement ('input');
radio.type = 'radio';
radio.name = '';
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;
}
});