input validation min and max
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
d29c011e5f
commit
b17852280b
|
@ -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;
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in New Issue