diff --git a/ui/src/views/setting/ConfigurationValue.vue b/ui/src/views/setting/ConfigurationValue.vue index 109931a6664..acee0f2eb6a 100644 --- a/ui/src/views/setting/ConfigurationValue.vue +++ b/ui/src/views/setting/ConfigurationValue.vue @@ -39,6 +39,7 @@ @keydown.esc="editableValueKey = null" @pressEnter="updateConfigurationValue(configrecord)" @change="value => setConfigurationEditable(configrecord, value)" + @keydown="e => handleInputNumberKeyDown(e, false)" /> @@ -52,6 +53,7 @@ @keydown.esc="editableValueKey = null" @pressEnter="updateConfigurationValue(configrecord)" @change="value => setConfigurationEditable(configrecord, value)" + @keydown="e => handleInputNumberKeyDown(e, true)" /> @@ -87,6 +89,7 @@ @keydown.esc="editableValueKey = null" @pressEnter="updateConfigurationValue(configrecord)" @change="value => setConfigurationEditable(configrecord, value)" + @keydown="e => handleInputNumberKeyDown(e, true)" /> @@ -350,6 +353,26 @@ export default { } else { this.editableValueKey = null } + }, + handleInputNumberKeyDown (event, isDecimal) { + const allowedCodes = ['Backspace', 'Delete', 'ArrowLeft', 'ArrowRight', 'Minus'] + + if (isDecimal) { + allowedCodes.push('Period') + } + + if ( + event.getModifierState('Control') || + event.getModifierState('Meta') || + event.getModifierState('Alt') + ) { + return + } + + const isValid = allowedCodes.includes(event.code) || !isNaN(event.key) + if (!isValid) { + event.preventDefault() + } } } }