Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
validate inserted values in numeric global settings
  • Loading branch information
bernardodemarco committed Jan 27, 2025
commit cf6398f5e483871ce851b7d5ab369ef8e6405c20
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