Skip to content

Commit 6e71238

Browse files
authored
feat(ui): validate number inputs against min/max from config (#4288)
Fixes #4285
1 parent 26f2e69 commit 6e71238

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/components/ValueId.vue

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,23 @@
5050
<v-text-field
5151
v-else-if="!value.list && value.type === 'number'"
5252
type="number"
53-
:append-outer-icon="!disable_send ? 'send' : null"
53+
:append-outer-icon="
54+
!disable_send && !numberOutOfRange ? 'send' : null
55+
"
5456
:suffix="value.unit"
5557
:min="value.min != value.max ? value.min : null"
5658
:step="value.step || 1"
5759
persistent-hint
5860
:max="value.min != value.max ? value.max : null"
5961
:hint="help"
62+
:error="numberOutOfRange"
63+
:error-messages="
64+
numberOutOfRange
65+
? `Value must be between ${value.min} and ${value.max}`
66+
: ''
67+
"
6068
v-model.number="value.newValue"
61-
@click:append-outer="updateValue(value)"
69+
@click:append-outer="!numberOutOfRange && updateValue(value)"
6270
></v-text-field>
6371

6472
<!-- Object Input -->
@@ -366,6 +374,14 @@ export default {
366374
? this.value.states.find((s) => s.value === true)?.text
367375
: null
368376
},
377+
numberOutOfRange() {
378+
const min = this.value.min ?? -Infinity
379+
const max = this.value.max ?? Infinity
380+
return (
381+
this.value.type === 'number' &&
382+
(this.value.newValue < min || this.value.newValue > max)
383+
)
384+
},
369385
falseLabel() {
370386
return this.value.type === 'boolean' &&
371387
this.value.states?.length > 0

0 commit comments

Comments
 (0)