Skip to content

Commit 876a293

Browse files
bernardodemarcodhslove
authored andcommitted
validate inserted values in numeric global settings (apache#10279)
1 parent fb6ae83 commit 876a293

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

ui/src/views/setting/ConfigurationValue.vue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
@keydown.esc="editableValueKey = null"
4040
@pressEnter="updateConfigurationValue(configrecord)"
4141
@change="value => setConfigurationEditable(configrecord, value)"
42+
@keydown="e => handleInputNumberKeyDown(e, false)"
4243
/>
4344
</a-tooltip>
4445
</span>
@@ -52,6 +53,7 @@
5253
@keydown.esc="editableValueKey = null"
5354
@pressEnter="updateConfigurationValue(configrecord)"
5455
@change="value => setConfigurationEditable(configrecord, value)"
56+
@keydown="e => handleInputNumberKeyDown(e, true)"
5557
/>
5658
</a-tooltip>
5759
</span>
@@ -87,6 +89,7 @@
8789
@keydown.esc="editableValueKey = null"
8890
@pressEnter="updateConfigurationValue(configrecord)"
8991
@change="value => setConfigurationEditable(configrecord, value)"
92+
@keydown="e => handleInputNumberKeyDown(e, true)"
9093
/>
9194
</a-tooltip>
9295
</a-col>
@@ -365,6 +368,26 @@ export default {
365368
} else {
366369
this.editableValueKey = null
367370
}
371+
},
372+
handleInputNumberKeyDown (event, isDecimal) {
373+
const allowedCodes = ['Backspace', 'Delete', 'ArrowLeft', 'ArrowRight', 'Minus']
374+
375+
if (isDecimal) {
376+
allowedCodes.push('Period')
377+
}
378+
379+
if (
380+
event.getModifierState('Control') ||
381+
event.getModifierState('Meta') ||
382+
event.getModifierState('Alt')
383+
) {
384+
return
385+
}
386+
387+
const isValid = allowedCodes.includes(event.code) || !isNaN(event.key)
388+
if (!isValid) {
389+
event.preventDefault()
390+
}
368391
}
369392
}
370393
}

0 commit comments

Comments
 (0)