Update number input on blur

This commit is contained in:
Rob Garrison 2018-09-20 03:34:37 -05:00
parent 93dee41c11
commit b0fbdfb6e9

View File

@ -264,6 +264,7 @@ function configDialog(style) {
va, va,
type: va.type, type: va.type,
onfocus: va.type === 'number' ? selectAllOnFocus : null, onfocus: va.type === 'number' ? selectAllOnFocus : null,
onblur: va.type === 'number' ? updateVarOnBlur : null,
onchange: updateVarOnChange, onchange: updateVarOnChange,
oninput: updateVarOnInput oninput: updateVarOnInput
}; };
@ -311,15 +312,23 @@ function configDialog(style) {
} }
} }
function updateVarOnBlur(e = {}) {
const value = Number(this.value);
const clamped = clampValue(value, this.va);
if (clamped === value) {
this.va.value = value;
}
if (e.type === 'blur') {
this.value = clamped;
}
}
function updateVarOnChange() { function updateVarOnChange() {
if (this.type === 'range') { if (this.type === 'range') {
this.va.value = Number(this.value); this.va.value = Number(this.value);
updateRangeCurrentValue(this.va, this.va.value); updateRangeCurrentValue(this.va, this.va.value);
} else if (this.type === 'number') { } else if (this.type === 'number') {
const value = Number(this.value); updateVarOnBlur.call(this);
if (clampValue(value, this.va) === value) {
this.va.value = value;
}
} else { } else {
this.va.value = this.type !== 'checkbox' ? this.value : this.checked ? '1' : '0'; this.va.value = this.type !== 'checkbox' ? this.value : this.checked ? '1' : '0';
} }