2018-09-13 09:27:38 +00:00
|
|
|
import ngModule from '../../module';
|
2019-10-08 21:57:02 +00:00
|
|
|
import Field from '../field';
|
2018-09-13 09:27:38 +00:00
|
|
|
|
2019-10-08 21:57:02 +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) {
|
2019-10-08 21:57:02 +00:00
|
|
|
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) {
|
2019-10-08 21:57:02 +00:00
|
|
|
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) {
|
2019-10-08 21:57:02 +00:00
|
|
|
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();
|
2019-10-08 21:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onStep(event, way) {
|
|
|
|
if (event.defaultPrevented) return;
|
|
|
|
|
|
|
|
if (way == 'up')
|
|
|
|
this.stepUp();
|
|
|
|
else
|
|
|
|
this.stepDown();
|
|
|
|
|
2019-10-01 09:15:15 +00:00
|
|
|
this.input.dispatchEvent(new Event('change'));
|
2018-09-13 09:27:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
ngModule.vnComponent('vnInputNumber', {
|
2018-09-13 09:27:38 +00:00
|
|
|
template: require('./index.html'),
|
|
|
|
controller: InputNumber,
|
|
|
|
bindings: {
|
|
|
|
min: '<?',
|
|
|
|
max: '<?',
|
|
|
|
step: '<?',
|
2019-10-08 21:57:02 +00:00
|
|
|
displayControls: '<?'
|
2018-09-13 09:27:38 +00:00
|
|
|
}
|
|
|
|
});
|