2018-09-13 09:27:38 +00:00
|
|
|
import ngModule from '../../module';
|
2019-04-04 09:53:13 +00:00
|
|
|
import Input from '../../lib/input';
|
2018-09-13 09:27:38 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
2019-04-04 09:53:13 +00:00
|
|
|
export default class InputNumber extends Input {
|
|
|
|
constructor($element, $scope, $attrs, vnTemplate) {
|
|
|
|
super($element, $scope);
|
2019-04-09 11:18:55 +00:00
|
|
|
this.displayControls = false;
|
2019-04-04 09:53:13 +00:00
|
|
|
this.hasFocus = false;
|
2019-04-09 11:18:55 +00:00
|
|
|
|
|
|
|
vnTemplate.normalizeInputAttrs($attrs);
|
2019-04-04 09:53:13 +00:00
|
|
|
this.registerEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers all event emitters
|
|
|
|
*/
|
|
|
|
registerEvents() {
|
2019-04-09 11:18:55 +00:00
|
|
|
this.input.addEventListener('change', event => {
|
2019-04-10 10:04:11 +00:00
|
|
|
this.validateValue();
|
2019-04-09 11:18:55 +00:00
|
|
|
this.emit('change', {event});
|
2018-09-13 09:27:38 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-09 11:18:55 +00:00
|
|
|
/**
|
|
|
|
* Gets current value
|
|
|
|
*/
|
2018-09-13 09:27:38 +00:00
|
|
|
get value() {
|
|
|
|
return this._value;
|
|
|
|
}
|
|
|
|
|
2019-04-09 11:18:55 +00:00
|
|
|
/**
|
|
|
|
* Sets input value
|
|
|
|
*
|
|
|
|
* @param {Number} value - Value
|
|
|
|
*/
|
2018-09-13 09:27:38 +00:00
|
|
|
set value(value) {
|
2019-04-11 06:05:46 +00:00
|
|
|
this.hasValue = !(value === null || value === undefined || value === '');
|
|
|
|
|
2019-05-15 13:26:13 +00:00
|
|
|
if (!this.hasOwnProperty('_value') && this.hasValue || value === '')
|
2019-04-10 10:04:11 +00:00
|
|
|
this.input.value = value;
|
|
|
|
|
2018-09-13 09:27:38 +00:00
|
|
|
this._value = value;
|
2019-10-01 09:15:15 +00:00
|
|
|
this.element.classList.toggle('not-empty', this.hasValue);
|
2019-04-09 11:18:55 +00:00
|
|
|
this.validateValue();
|
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-04-09 11:18:55 +00:00
|
|
|
if (value) this.input.max = value;
|
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-04-11 05:29:41 +00:00
|
|
|
if (value) this.input.min = value;
|
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-04-11 05:29:41 +00:00
|
|
|
if (value) this.input.step = value;
|
2018-09-13 09:27:38 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 11:18:55 +00:00
|
|
|
/**
|
|
|
|
* Increases the input value
|
|
|
|
*/
|
|
|
|
stepUp() {
|
|
|
|
this.input.stepUp();
|
2019-10-01 09:15:15 +00:00
|
|
|
this.input.dispatchEvent(new Event('change'));
|
2018-09-13 09:27:38 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 11:18:55 +00:00
|
|
|
/**
|
|
|
|
* Decreases the input value
|
|
|
|
*/
|
|
|
|
stepDown() {
|
|
|
|
this.input.stepDown();
|
2019-10-01 09:15:15 +00:00
|
|
|
this.input.dispatchEvent(new Event('change'));
|
2018-09-13 09:27:38 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-09 11:18:55 +00:00
|
|
|
InputNumber.$inject = ['$element', '$scope', '$attrs', 'vnTemplate'];
|
2018-09-13 09:27:38 +00:00
|
|
|
|
|
|
|
ngModule.component('vnInputNumber', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: InputNumber,
|
2019-06-06 11:59:11 +00:00
|
|
|
transclude: {
|
|
|
|
leftIcons: '?tLeftIcons',
|
|
|
|
rightIcons: '?tRightIcons'
|
|
|
|
},
|
2018-09-13 09:27:38 +00:00
|
|
|
bindings: {
|
|
|
|
label: '@?',
|
2019-03-26 06:29:45 +00:00
|
|
|
name: '@?',
|
2018-09-13 09:27:38 +00:00
|
|
|
disabled: '<?',
|
2019-06-26 11:35:38 +00:00
|
|
|
required: '@?',
|
2018-09-13 09:27:38 +00:00
|
|
|
min: '<?',
|
|
|
|
max: '<?',
|
|
|
|
step: '<?',
|
2019-02-25 14:56:42 +00:00
|
|
|
displayControls: '<?',
|
2018-09-13 09:27:38 +00:00
|
|
|
rule: '@?',
|
|
|
|
value: '=model',
|
|
|
|
validate: '&',
|
|
|
|
onChange: '&',
|
|
|
|
onClear: '&'
|
|
|
|
}
|
|
|
|
});
|