2018-02-10 15:18:01 +00:00
|
|
|
import ngModule from '../../module';
|
2019-10-04 10:33:16 +00:00
|
|
|
import Toggle from '../toggle';
|
2018-02-12 12:16:49 +00:00
|
|
|
import './style.scss';
|
2018-02-10 15:18:01 +00:00
|
|
|
|
2019-10-01 09:15:15 +00:00
|
|
|
/**
|
|
|
|
* Basic element for user input. You can use this to supply a way for the user
|
|
|
|
* to pick an option from multiple choices.
|
|
|
|
*
|
|
|
|
* @property {String} val The actual value of the option
|
|
|
|
*/
|
2019-10-04 10:33:16 +00:00
|
|
|
export default class Radio extends Toggle {
|
2019-09-30 18:46:22 +00:00
|
|
|
set field(value) {
|
2019-10-09 22:47:29 +00:00
|
|
|
super.field = value;
|
2019-10-01 09:15:15 +00:00
|
|
|
this.element.classList.toggle('checked',
|
|
|
|
Boolean(value) && value == this.val);
|
2019-09-30 18:46:22 +00:00
|
|
|
}
|
2019-02-15 07:02:29 +00:00
|
|
|
|
2019-09-30 18:46:22 +00:00
|
|
|
get field() {
|
2019-10-09 22:47:29 +00:00
|
|
|
return super.field;
|
2019-09-30 18:46:22 +00:00
|
|
|
}
|
2019-02-14 19:17:22 +00:00
|
|
|
|
2019-10-01 09:15:15 +00:00
|
|
|
set checked(value) {
|
|
|
|
this.field = value ? this.val : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
get checked() {
|
|
|
|
return this.field == this.val;
|
|
|
|
}
|
|
|
|
|
2019-10-04 10:33:16 +00:00
|
|
|
set val(value) {
|
|
|
|
this._val = value;
|
|
|
|
this.field = this.field;
|
2019-02-14 19:17:22 +00:00
|
|
|
}
|
|
|
|
|
2019-10-04 10:33:16 +00:00
|
|
|
get val() {
|
|
|
|
return this._val;
|
2019-09-30 18:46:22 +00:00
|
|
|
}
|
2019-02-14 19:17:22 +00:00
|
|
|
|
2019-09-30 18:46:22 +00:00
|
|
|
onClick(event) {
|
2019-10-04 10:33:16 +00:00
|
|
|
if (super.onClick(event)) return;
|
2019-10-28 20:40:24 +00:00
|
|
|
this.change(this.val);
|
2018-02-12 12:16:49 +00:00
|
|
|
}
|
2018-02-10 15:18:01 +00:00
|
|
|
}
|
2019-02-15 12:31:14 +00:00
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
ngModule.vnComponent('vnRadio', {
|
2019-10-04 10:33:16 +00:00
|
|
|
template: require('../toggle/index.html'),
|
|
|
|
controller: Radio,
|
2018-02-12 12:16:49 +00:00
|
|
|
bindings: {
|
2019-10-04 10:33:16 +00:00
|
|
|
val: '@?'
|
2018-02-12 12:16:49 +00:00
|
|
|
}
|
|
|
|
});
|