input validation min and max
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Вячеслав Нагель 2023-07-03 13:32:04 +07:00
parent d29c011e5f
commit b17852280b
Signed by: v9gel
GPG Key ID: 7C2360915BE4C743
2 changed files with 22 additions and 3 deletions

View File

@ -59,7 +59,7 @@ const rotatePage = () => {
</SidebarBlock> </SidebarBlock>
<SidebarBlock title="Вертикальные линии"> <SidebarBlock title="Вертикальные линии">
<Input v-model="vMargin" :min="1">Отступ, мм</Input> <Input v-model="vMargin" :min="1">Отступ, мм</Input>
<Input v-model="vRotation">Поворот, градусы</Input> <Input v-model="vRotation" :min="0" :max="359">Поворот, градусы</Input>
<ButtonsBar> <ButtonsBar>
<Button :size="ButtonSize.Small" :click="() => { <Button :size="ButtonSize.Small" :click="() => {
vRotation = 45; vRotation = 45;

View File

@ -1,4 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { onUpdated } from 'vue';
import { InputType } from '../types'; import { InputType } from '../types';
interface Props { interface Props {
@ -7,11 +8,29 @@ interface Props {
max?: number; max?: number;
} }
withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
type: InputType.Number, type: InputType.Number,
}) })
const modelValue = defineModel(); const modelValue = defineModel<number | string>();
onUpdated(() => {
// Задать граничное значение при выходе за допуустимые пределы
if (props.type === InputType.Number && typeof modelValue.value === 'number') {
if (props.min !== undefined) {
if (modelValue.value < props.min) {
modelValue.value = props.min
}
}
if (props.max !== undefined) {
if (modelValue.value > props.max) {
modelValue.value = props.max
}
}
}
})
</script> </script>
<template> <template>