fixed input time

This commit is contained in:
Joan Sanchez 2019-04-10 12:04:11 +02:00
parent 2be3481138
commit 6f98d81db1
3 changed files with 56 additions and 21 deletions

View File

@ -21,6 +21,8 @@ export default class InputNumber extends Input {
if (!isNaN(this.value))
this.input.value = this.value;
this.validateValue();
this.emit('change', {event});
});
@ -42,8 +44,11 @@ export default class InputNumber extends Input {
* @param {Number} value - Value
*/
set value(value) {
if (!this.hasOwnProperty('_value') && value)
this.input.value = value;
this._value = value;
this.hasValue = this._value !== null;
this.hasValue = !(value === null || value === undefined || value === '');
if (this.hasValue)
this.element.classList.add('not-empty');
@ -102,6 +107,10 @@ export default class InputNumber extends Input {
this.input.step = value;
}
get validationError() {
return this.input.validationMessage;
}
/**
* Increases the input value
*/
@ -131,12 +140,42 @@ export default class InputNumber extends Input {
*/
validateValue() {
if (!this.hasValidValue()) {
this.element.querySelector('.infix')
.classList.add('invalid', 'validated');
} else {
this.element.querySelector('.infix')
.classList.remove('invalid', 'validated');
}
this.hideError();
this.showError();
} else
this.hideError();
}
/**
* Shows the input validation error
*/
showError() {
const infixElement = this.element.querySelector('.infix');
const infixClassList = infixElement.classList;
const errorSpan = document.createElement('span');
errorSpan.className = 'mdl-textfield__error';
const errorText = document.createTextNode(this.validationError);
errorSpan.append(errorText);
infixElement.append(errorSpan);
infixClassList.add('validated', 'invalid');
}
/**
* Hides the input validation error
*/
hideError() {
const infixElement = this.element.querySelector('.infix');
const infixClassList = infixElement.classList;
const errorElement = this.element.querySelector('.infix span.mdl-textfield__error');
if (errorElement)
errorElement.remove();
infixClassList.remove('validated', 'invalid');
}
}

View File

@ -50,7 +50,7 @@ describe('Component vnInputNumber', () => {
controller.validateValue();
let classes = controller.element.querySelector('.infix').classList.toString();
expect(classes).not.toContain('invalid validated');
expect(classes).not.toContain('validated invalid');
});
it(`should call hasValidValue() and add the class invalid and validated`, () => {
@ -60,7 +60,7 @@ describe('Component vnInputNumber', () => {
controller.validateValue();
let classes = controller.element.querySelector('.infix').classList.toString();
expect(classes).toContain('invalid validated');
expect(classes).toContain('validated invalid');
});
});
});

View File

@ -32,31 +32,27 @@
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-input-number
vn-two
min="0"
step="1"
<vn-input-number vn-two
label="Traveling days"
field="$ctrl.zone.travelingDays">
model="$ctrl.zone.travelingDays"
min="0" step="1">
</vn-input-number>
<vn-input-time
vn-two
label="Estimated hour (ETD)"
field="$ctrl.zone.hour">
model="$ctrl.zone.hour">
</vn-input-time>
</vn-horizontal>
<vn-horizontal>
<vn-input-number vn-one
label="Price"
field="$ctrl.zone.price"
min="0"
step="0.10">
model="$ctrl.zone.price"
min="0" step="0.01">
</vn-input-number>
<vn-input-number vn-one
label="Bonus"
field="$ctrl.zone.bonus"
min="0"
step="0.10">
model="$ctrl.zone.bonus"
min="0" step="0.01">
</vn-input-number>
</vn-horizontal>
<vn-horizontal>