Skip to content

Commit 2ee5c9e

Browse files
bernardodemarcoGlover, Rene (rg9975)
authored andcommitted
validate inserted values in numeric global settings (apache#10279)
1 parent 73279ad commit 2ee5c9e

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>
@@ -350,6 +353,26 @@ export default {
350353
} else {
351354
this.editableValueKey = null
352355
}
356+
},
357+
handleInputNumberKeyDown (event, isDecimal) {
358+
const allowedCodes = ['Backspace', 'Delete', 'ArrowLeft', 'ArrowRight', 'Minus']
359+
360+
if (isDecimal) {
361+
allowedCodes.push('Period')
362+
}
363+
364+
if (
365+
event.getModifierState('Control') ||
366+
event.getModifierState('Meta') ||
367+
event.getModifierState('Alt')
368+
) {
369+
return
370+
}
371+
372+
const isValid = allowedCodes.includes(event.code) || !isNaN(event.key)
373+
if (!isValid) {
374+
event.preventDefault()
375+
}
353376
}
354377
}
355378
}

0 commit comments

Comments
 (0)