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) {
|
|
|
|
this._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() {
|
|
|
|
return this._field;
|
|
|
|
}
|
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-01 09:15:15 +00:00
|
|
|
this.field = this.val;
|
2019-10-04 10:33:16 +00:00
|
|
|
this.changed();
|
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-01 09:15:15 +00:00
|
|
|
ngModule.component('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: {
|
|
|
|
label: '@?',
|
2019-10-01 09:15:15 +00:00
|
|
|
field: '=?',
|
2019-10-04 10:33:16 +00:00
|
|
|
disabled: '<?',
|
2019-02-14 19:17:22 +00:00
|
|
|
checked: '<?',
|
2019-10-04 10:33:16 +00:00
|
|
|
val: '@?'
|
2018-02-12 12:16:49 +00:00
|
|
|
}
|
|
|
|
});
|