diff --git a/front/core/components/input-number/index.html b/front/core/components/input-number/index.html
index ec34c43ca..cb3f24bd5 100644
--- a/front/core/components/input-number/index.html
+++ b/front/core/components/input-number/index.html
@@ -5,7 +5,7 @@
@@ -30,7 +30,7 @@
diff --git a/front/core/components/input-number/index.js b/front/core/components/input-number/index.js
index bfd78453f..458c6d61f 100644
--- a/front/core/components/input-number/index.js
+++ b/front/core/components/input-number/index.js
@@ -5,9 +5,11 @@ import './style.scss';
export default class InputNumber extends Input {
constructor($element, $scope, $attrs, vnTemplate) {
super($element, $scope);
- vnTemplate.normalizeInputAttrs($attrs);
- this.displayControls = true;
+ this.displayControls = false;
this.hasFocus = false;
+
+ vnTemplate.normalizeInputAttrs($attrs);
+
this.registerEvents();
}
@@ -15,8 +17,11 @@ export default class InputNumber extends Input {
* Registers all event emitters
*/
registerEvents() {
- this.input.addEventListener('change', () => {
- this.validateValue();
+ this.input.addEventListener('change', event => {
+ if (!isNaN(this.value))
+ this.input.value = this.value;
+
+ this.emit('change', {event});
});
this.input.addEventListener('focus', event => {
@@ -24,80 +29,118 @@ export default class InputNumber extends Input {
});
}
+ /**
+ * Gets current value
+ */
get value() {
return this._value;
}
+ /**
+ * Sets input value
+ *
+ * @param {Number} value - Value
+ */
set value(value) {
this._value = value;
this.hasValue = this._value !== null;
- this.input.value = this._value;
- if (this.hasValue) this.element.classList.add('not-empty');
- else this.element.classList.remove('not-empty');
+ if (this.hasValue)
+ this.element.classList.add('not-empty');
+ else
+ this.element.classList.remove('not-empty');
- this.element.querySelector('.infix').classList.remove('invalid', 'validated');
+ this.validateValue();
}
+ /**
+ * Gets max value
+ */
get max() {
return this.input.max;
}
+ /**
+ * Sets max allowed value
+ *
+ * @param {Number} value - Value
+ */
set max(value) {
- if (value)
- this.input.max = value;
+ if (value) this.input.max = value;
}
+ /**
+ * Gets min value
+ */
get min() {
return this.input.min;
}
+ /**
+ * Sets min allowed value
+ *
+ * @param {Number} value - Value
+ */
set min(value) {
if (!value) value = 0;
this.input.min = value;
}
+ /**
+ * Gets min step value
+ */
get step() {
return parseFloat(this.input.step);
}
+ /**
+ * Sets min step value
+ *
+ * @param {Number} value - Value
+ */
set step(value) {
this.input.step = value;
}
+ /**
+ * Increases the input value
+ */
+ stepUp() {
+ this.input.stepUp();
+ }
+
+ /**
+ * Decreases the input value
+ */
+ stepDown() {
+ this.input.stepDown();
+ }
+
+ /**
+ * Validates a valid input value
+ *
+ * @return {Boolean} - True if has a valid value
+ */
+ hasValidValue() {
+ return this.input.checkValidity();
+ }
+
+ /**
+ * Changes the input element
+ * if has a validation error
+ */
validateValue() {
- if ((this.validate() !== undefined && !this.validate()) ||
- (this.max && this.value > this.max) ||
- (this.min && this.value < this.min) ||
- (this.displayControls && (this.step && this.value % this.step != 0)))
- this.$element[0].querySelector('.infix').classList.add('invalid', 'validated');
-
-
- if (this.onChange)
- this.onChange();
- }
-
- add() {
- if (this.step && this.value % this.step != 0)
- this.value += (this.step - this.value % this.step);
- else
- this.value += this.step;
-
-
- this.validateValue();
- }
-
- remove() {
- if (this.step && this.value % this.step != 0)
- this.value -= (this.step + this.value % this.step);
- else
- this.value -= this.step;
-
- this.validateValue();
+ if (!this.hasValidValue()) {
+ this.element.querySelector('.infix')
+ .classList.add('invalid', 'validated');
+ } else {
+ this.element.querySelector('.infix')
+ .classList.remove('invalid', 'validated');
+ }
}
}
-InputNumber.$inject = ['$element', '$scope', '$attrs', 'vnTemplate', '$transclude'];
+InputNumber.$inject = ['$element', '$scope', '$attrs', 'vnTemplate'];
ngModule.component('vnInputNumber', {
template: require('./index.html'),
diff --git a/front/core/components/input-number/index.spec.js b/front/core/components/input-number/index.spec.js
index 886b2948b..18d51512e 100644
--- a/front/core/components/input-number/index.spec.js
+++ b/front/core/components/input-number/index.spec.js
@@ -12,144 +12,55 @@ describe('Component vnInputNumber', () => {
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
$scope = $rootScope.$new();
$attrs = {};
- $element = angular.element('
');
+ $element = angular.element('
');
controller = $componentController('vnInputNumber', {$element, $scope, $attrs, $timeout, $transclude: () => {}});
+ controller.input = $element[0].querySelector('input');
+ controller.validate = () => {};
}));
describe('value() setter', () => {
- it(`should set _value to a given value, add the class not-empty and remove invalid and validated`, () => {
- controller.value = 'pepino';
+ it(`should set a value, add the class 'not-empty' and then call validateValue() method`, () => {
+ spyOn(controller, 'validateValue');
+
+ controller.value = 10;
+
let classes = controller.element.classList.toString();
expect(classes).toContain('not-empty');
- expect(controller._value).toEqual('pepino');
-
- classes = controller.element.querySelector('.infix').classList.toString();
-
- expect(classes).not.toContain('invalid validated');
+ expect(controller.validateValue).toHaveBeenCalledWith();
});
- it(`should set _value to a given value and not add the class not-empty if the given value is null`, () => {
+ it(`should set an empty value, remove the class 'not-empty' and then call validateValue() method`, () => {
+ spyOn(controller, 'validateValue');
+
controller.value = null;
+
let classes = controller.element.classList.toString();
expect(classes).not.toContain('not-empty');
- expect(controller._value).toEqual(null);
- });
- });
-
- describe('max() setter', () => {
- it(`should set input.max to a given value`, () => {
- controller.max = 10;
-
- expect(controller.input.max).toEqual('10');
- });
- });
-
- describe('min() setter', () => {
- it(`should set input.min if theres a given value`, () => {
- controller.min = 1;
-
- expect(controller.input.min).toEqual('1');
- });
-
- it(`should set input.min to 0 if theres not a given value`, () => {
- controller.min = null;
-
- expect(controller.input.min).toEqual('0');
- });
- });
-
- describe('step() setter/getter', () => {
- it(`should set input.step to a given value`, () => {
- controller.step = 50;
-
- expect(controller.input.step).toEqual('50');
- });
-
- it(`should return a number`, () => {
- controller.step = 50;
-
- expect(controller.step).toEqual(50);
- expect(typeof controller.step).toEqual('number');
+ expect(controller.validateValue).toHaveBeenCalledWith();
});
});
describe('validateValue()', () => {
- it(`should add the classes invalid and validated if the value is less than min`, () => {
- controller.validate = () => {};
- controller.min = 0;
- controller.value = -7;
+ it(`should call hasValidValue() and not add the class invalid and validated`, () => {
+ controller.input.min = 0;
+ controller.input.value = 10;
+
+ controller.validateValue();
let classes = controller.element.querySelector('.infix').classList.toString();
expect(classes).not.toContain('invalid validated');
- expect(controller.value).toEqual(-7);
-
- controller.validateValue();
- classes = controller.element.querySelector('.infix').classList.toString();
-
- expect(classes).toContain('infix invalid validated');
});
- it(`should add the classes invalid and validated if the value is greater than max`, () => {
- controller.validate = () => {};
- controller.max = 10;
- controller.value = 15;
+ it(`should call hasValidValue() and add the class invalid and validated`, () => {
+ controller.input.min = 0;
+ controller.input.value = -10;
+
+ controller.validateValue();
let classes = controller.element.querySelector('.infix').classList.toString();
- expect(classes).not.toContain('invalid validated');
- expect(controller.value).toEqual(15);
-
- controller.validateValue();
- classes = controller.element.querySelector('.infix').classList.toString();
-
- expect(classes).toContain('infix invalid validated');
- });
-
- it(`should add the classes invalid and validated if the value is not a valid step`, () => {
- controller.validate = () => {};
- controller.step = 5;
- controller.value = 7;
- let classes = controller.element.querySelector('.infix').classList.toString();
-
- expect(classes).not.toContain('invalid validated');
- expect(controller.value).toEqual(7);
-
- controller.validateValue();
- classes = controller.element.querySelector('.infix').classList.toString();
-
- expect(classes).toContain('infix invalid validated');
- });
-
- it(`should add the classes invalid and validated if the function validate returns false`, () => {
- controller.validate = () => {
- return false;
- };
- controller.step = 5;
- controller.value = 7;
- let classes = controller.element.querySelector('.infix').classList.toString();
-
- expect(classes).not.toContain('invalid validated');
- expect(controller.value).toEqual(7);
-
- controller.validateValue();
- classes = controller.element.querySelector('.infix').classList.toString();
-
- expect(classes).toContain('infix invalid validated');
- });
- });
-
- describe('add()', () => {
- it(`should set value to the next possible step and call validateValue`, () => {
- spyOn(controller, 'validateValue');
-
- controller.step = 50;
- controller.value = -1;
-
- controller.remove();
-
- expect(controller.value).toEqual(-50);
- expect(controller.validateValue).toHaveBeenCalledWith();
+ expect(classes).toContain('invalid validated');
});
});
});
diff --git a/modules/agency/front/basic-data/index.html b/modules/agency/front/basic-data/index.html
index 434322d14..1dfeaa1c6 100644
--- a/modules/agency/front/basic-data/index.html
+++ b/modules/agency/front/basic-data/index.html
@@ -37,8 +37,7 @@
min="0"
step="1"
label="Traveling days"
- field="$ctrl.zone.travelingDays"
- display-controls="false">
+ field="$ctrl.zone.travelingDays">
+ step="0.10">
+ step="0.10">
diff --git a/modules/agency/front/create/index.html b/modules/agency/front/create/index.html
index 124c4e482..eef4be8ba 100644
--- a/modules/agency/front/create/index.html
+++ b/modules/agency/front/create/index.html
@@ -39,8 +39,7 @@
value="$ctrl.zone.travelingDays"
step="1"
label="Traveling days"
- field="$ctrl.zone.travelingDays"
- display-controls="false">
+ field="$ctrl.zone.travelingDays">
+ step="0.10">
+ step="0.10">
diff --git a/modules/claim/front/detail/index.html b/modules/claim/front/detail/index.html
index dbdd98403..fde90835d 100644
--- a/modules/claim/front/detail/index.html
+++ b/modules/claim/front/detail/index.html
@@ -47,7 +47,6 @@
diff --git a/modules/client/front/credit-insurance/create/index.html b/modules/client/front/credit-insurance/create/index.html
index d1903ad0e..c635f75d6 100644
--- a/modules/client/front/credit-insurance/create/index.html
+++ b/modules/client/front/credit-insurance/create/index.html
@@ -2,14 +2,12 @@
diff --git a/modules/client/front/credit-insurance/insurance/create/index.html b/modules/client/front/credit-insurance/insurance/create/index.html
index f90a80ea6..f6770b29a 100644
--- a/modules/client/front/credit-insurance/insurance/create/index.html
+++ b/modules/client/front/credit-insurance/insurance/create/index.html
@@ -9,9 +9,8 @@
@@ -23,7 +22,6 @@
diff --git a/modules/client/front/credit/create/index.html b/modules/client/front/credit/create/index.html
index b16219005..02a55a8b7 100644
--- a/modules/client/front/credit/create/index.html
+++ b/modules/client/front/credit/create/index.html
@@ -8,9 +8,7 @@
diff --git a/modules/item/front/data/index.html b/modules/item/front/data/index.html
index 288d534f6..4f9bf3366 100644
--- a/modules/item/front/data/index.html
+++ b/modules/item/front/data/index.html
@@ -63,25 +63,21 @@
field="$ctrl.item.comment">
-
-
-
diff --git a/modules/ticket/front/package/index.html b/modules/ticket/front/package/index.html
index c718d74fc..5fbfffcf5 100644
--- a/modules/ticket/front/package/index.html
+++ b/modules/ticket/front/package/index.html
@@ -26,7 +26,6 @@
{{itemFk}} : {{name}}
diff --git a/modules/ticket/front/request/create/index.html b/modules/ticket/front/request/create/index.html
index 26878a906..95ea8b550 100644
--- a/modules/ticket/front/request/create/index.html
+++ b/modules/ticket/front/request/create/index.html
@@ -22,13 +22,11 @@
-
-
diff --git a/modules/ticket/front/services/index.html b/modules/ticket/front/services/index.html
index 3e5249593..a4229b435 100644
--- a/modules/ticket/front/services/index.html
+++ b/modules/ticket/front/services/index.html
@@ -26,10 +26,9 @@
model="service.quantity"
rule="TicketService.quantity">
-
+ model="service.price" step="0.01">