From b0fbdfb6e9a0ca57f997bf13057185761ea9a974 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Thu, 20 Sep 2018 03:34:37 -0500 Subject: [PATCH] Update number input on blur --- manage/config-dialog.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/manage/config-dialog.js b/manage/config-dialog.js index 65734a5f..c314f2e0 100644 --- a/manage/config-dialog.js +++ b/manage/config-dialog.js @@ -264,6 +264,7 @@ function configDialog(style) { va, type: va.type, onfocus: va.type === 'number' ? selectAllOnFocus : null, + onblur: va.type === 'number' ? updateVarOnBlur : null, onchange: updateVarOnChange, 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() { if (this.type === 'range') { this.va.value = Number(this.value); updateRangeCurrentValue(this.va, this.va.value); } else if (this.type === 'number') { - const value = Number(this.value); - if (clampValue(value, this.va) === value) { - this.va.value = value; - } + updateVarOnBlur.call(this); } else { this.va.value = this.type !== 'checkbox' ? this.value : this.checked ? '1' : '0'; }