Skip to content

Commit

Permalink
validate inserted values in numeric global settings (#10279)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardodemarco authored Jan 30, 2025
1 parent 1c84ce4 commit 6f03f9e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ui/src/views/setting/ConfigurationValue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
@keydown.esc="editableValueKey = null"
@pressEnter="updateConfigurationValue(configrecord)"
@change="value => setConfigurationEditable(configrecord, value)"
@keydown="e => handleInputNumberKeyDown(e, false)"
/>
</a-tooltip>
</span>
Expand All @@ -52,6 +53,7 @@
@keydown.esc="editableValueKey = null"
@pressEnter="updateConfigurationValue(configrecord)"
@change="value => setConfigurationEditable(configrecord, value)"
@keydown="e => handleInputNumberKeyDown(e, true)"
/>
</a-tooltip>
</span>
Expand Down Expand Up @@ -87,6 +89,7 @@
@keydown.esc="editableValueKey = null"
@pressEnter="updateConfigurationValue(configrecord)"
@change="value => setConfigurationEditable(configrecord, value)"
@keydown="e => handleInputNumberKeyDown(e, true)"
/>
</a-tooltip>
</a-col>
Expand Down Expand Up @@ -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()
}
}
}
}
Expand Down

0 comments on commit 6f03f9e

Please sign in to comment.