validate inserted values in numeric global settings (#10279)

This commit is contained in:
Bernardo De Marco Gonçalves 2025-01-30 08:00:32 -03:00 committed by GitHub
parent 1c84ce4e23
commit 6f03f9e726
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -39,6 +39,7 @@
@keydown.esc="editableValueKey = null" @keydown.esc="editableValueKey = null"
@pressEnter="updateConfigurationValue(configrecord)" @pressEnter="updateConfigurationValue(configrecord)"
@change="value => setConfigurationEditable(configrecord, value)" @change="value => setConfigurationEditable(configrecord, value)"
@keydown="e => handleInputNumberKeyDown(e, false)"
/> />
</a-tooltip> </a-tooltip>
</span> </span>
@ -52,6 +53,7 @@
@keydown.esc="editableValueKey = null" @keydown.esc="editableValueKey = null"
@pressEnter="updateConfigurationValue(configrecord)" @pressEnter="updateConfigurationValue(configrecord)"
@change="value => setConfigurationEditable(configrecord, value)" @change="value => setConfigurationEditable(configrecord, value)"
@keydown="e => handleInputNumberKeyDown(e, true)"
/> />
</a-tooltip> </a-tooltip>
</span> </span>
@ -87,6 +89,7 @@
@keydown.esc="editableValueKey = null" @keydown.esc="editableValueKey = null"
@pressEnter="updateConfigurationValue(configrecord)" @pressEnter="updateConfigurationValue(configrecord)"
@change="value => setConfigurationEditable(configrecord, value)" @change="value => setConfigurationEditable(configrecord, value)"
@keydown="e => handleInputNumberKeyDown(e, true)"
/> />
</a-tooltip> </a-tooltip>
</a-col> </a-col>
@ -350,6 +353,26 @@ export default {
} else { } else {
this.editableValueKey = null 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()
}
} }
} }
} }