Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.19 merge #10303

Closed
wants to merge 12 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
validate inserted values in numeric global settings (#10279)
bernardodemarco authored Jan 30, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 6f03f9e726ef099f63e8c92950282950e83e1c80
23 changes: 23 additions & 0 deletions ui/src/views/setting/ConfigurationValue.vue
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@
@keydown.esc="editableValueKey = null"
@pressEnter="updateConfigurationValue(configrecord)"
@change="value => setConfigurationEditable(configrecord, value)"
@keydown="e => handleInputNumberKeyDown(e, false)"
/>
</a-tooltip>
</span>
@@ -52,6 +53,7 @@
@keydown.esc="editableValueKey = null"
@pressEnter="updateConfigurationValue(configrecord)"
@change="value => setConfigurationEditable(configrecord, value)"
@keydown="e => handleInputNumberKeyDown(e, true)"
/>
</a-tooltip>
</span>
@@ -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>
@@ -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()
}
}
}
}