salix/front/core/components/input-number/index.js

91 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-09-13 09:27:38 +00:00
import ngModule from '../../module';
import Field from '../field';
2018-09-13 09:27:38 +00:00
export default class InputNumber extends Field {
constructor($element, $scope, $compile) {
super($element, $scope, $compile);
this.buildInput('number');
2018-09-13 09:27:38 +00:00
}
2019-04-09 11:18:55 +00:00
/**
* Gets max value
*/
2018-09-13 09:27:38 +00:00
get max() {
return this.input.max;
}
2019-04-09 11:18:55 +00:00
/**
* Sets max allowed value
*
* @param {Number} value - Value
*/
2018-09-13 09:27:38 +00:00
set max(value) {
this.input.max = value;
this.validateValue();
2018-09-13 09:27:38 +00:00
}
2019-04-09 11:18:55 +00:00
/**
* Gets min value
*/
2018-09-13 09:27:38 +00:00
get min() {
return this.input.min;
}
2019-04-09 11:18:55 +00:00
/**
* Sets min allowed value
*
* @param {Number} value - Value
*/
2018-09-13 09:27:38 +00:00
set min(value) {
this.input.min = value;
this.validateValue();
2018-09-13 09:27:38 +00:00
}
2019-04-09 11:18:55 +00:00
/**
* Gets min step value
*/
2018-09-13 09:27:38 +00:00
get step() {
2018-09-19 13:05:07 +00:00
return parseFloat(this.input.step);
2018-09-13 09:27:38 +00:00
}
2019-04-09 11:18:55 +00:00
/**
* Sets min step value
*
* @param {Number} value - Value
*/
2018-09-13 09:27:38 +00:00
set step(value) {
this.input.step = value;
this.validateValue();
2018-09-13 09:27:38 +00:00
}
2019-04-09 11:18:55 +00:00
stepUp() {
this.input.stepUp();
2018-09-13 09:27:38 +00:00
}
2019-04-09 11:18:55 +00:00
stepDown() {
this.input.stepDown();
}
onStep(event, way) {
if (event.defaultPrevented) return;
if (way == 'up')
this.stepUp();
else
this.stepDown();
this.input.dispatchEvent(new Event('change'));
2018-09-13 09:27:38 +00:00
}
}
ngModule.vnComponent('vnInputNumber', {
2018-09-13 09:27:38 +00:00
template: require('./index.html'),
controller: InputNumber,
bindings: {
min: '<?',
max: '<?',
step: '<?',
displayControls: '<?'
2018-09-13 09:27:38 +00:00
}
});