hedera-web/js/htk/field/radio.js

84 lines
1.6 KiB
JavaScript
Raw Normal View History

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