fix: don't allow negative repeat amounts
Partial fix for https://kolaente.dev/vikunja/frontend/issues/2179
This commit is contained in:
parent
8183fce829
commit
71c8540c74
2 changed files with 28 additions and 8 deletions
|
@ -1,9 +1,15 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="control repeat-after-input">
|
<div class="control repeat-after-input">
|
||||||
<div class="buttons has-addons is-centered mt-2">
|
<div class="buttons has-addons is-centered mt-2">
|
||||||
<x-button variant="secondary" class="is-small" @click="() => setRepeatAfter(1, 'days')">{{ $t('task.repeat.everyDay') }}</x-button>
|
<x-button variant="secondary" class="is-small" @click="() => setRepeatAfter(1, 'days')">
|
||||||
<x-button variant="secondary" class="is-small" @click="() => setRepeatAfter(1, 'weeks')">{{ $t('task.repeat.everyWeek') }}</x-button>
|
{{ $t('task.repeat.everyDay') }}
|
||||||
<x-button variant="secondary" class="is-small" @click="() => setRepeatAfter(1, 'months')">{{ $t('task.repeat.everyMonth') }}</x-button>
|
</x-button>
|
||||||
|
<x-button variant="secondary" class="is-small" @click="() => setRepeatAfter(1, 'weeks')">
|
||||||
|
{{ $t('task.repeat.everyWeek') }}
|
||||||
|
</x-button>
|
||||||
|
<x-button variant="secondary" class="is-small" @click="() => setRepeatAfter(1, 'months')">
|
||||||
|
{{ $t('task.repeat.everyMonth') }}
|
||||||
|
</x-button>
|
||||||
</div>
|
</div>
|
||||||
<div class="is-flex is-align-items-center mb-2">
|
<div class="is-flex is-align-items-center mb-2">
|
||||||
<label for="repeatMode" class="is-fullwidth">
|
<label for="repeatMode" class="is-fullwidth">
|
||||||
|
@ -14,7 +20,10 @@
|
||||||
<select @change="updateData" v-model="task.repeatMode" id="repeatMode">
|
<select @change="updateData" v-model="task.repeatMode" id="repeatMode">
|
||||||
<option :value="repeatModes.REPEAT_MODE_DEFAULT">{{ $t('misc.default') }}</option>
|
<option :value="repeatModes.REPEAT_MODE_DEFAULT">{{ $t('misc.default') }}</option>
|
||||||
<option :value="repeatModes.REPEAT_MODE_MONTH">{{ $t('task.repeat.monthly') }}</option>
|
<option :value="repeatModes.REPEAT_MODE_MONTH">{{ $t('task.repeat.monthly') }}</option>
|
||||||
<option :value="repeatModes.REPEAT_MODE_FROM_CURRENT_DATE">{{ $t('task.repeat.fromCurrentDate') }}</option>
|
<option :value="repeatModes.REPEAT_MODE_FROM_CURRENT_DATE">{{
|
||||||
|
$t('task.repeat.fromCurrentDate')
|
||||||
|
}}
|
||||||
|
</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -32,6 +41,7 @@
|
||||||
:placeholder="$t('task.repeat.specifyAmount')"
|
:placeholder="$t('task.repeat.specifyAmount')"
|
||||||
v-model="repeatAfter.amount"
|
v-model="repeatAfter.amount"
|
||||||
type="number"
|
type="number"
|
||||||
|
min="0"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
|
@ -56,8 +66,10 @@
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {ref, reactive, watch} from 'vue'
|
import {ref, reactive, watch} from 'vue'
|
||||||
import repeatModes from '@/models/constants/taskRepeatModes'
|
import repeatModes from '@/models/constants/taskRepeatModes.json'
|
||||||
import TaskModel from '@/models/task'
|
import TaskModel from '@/models/task'
|
||||||
|
import {error} from '@/message'
|
||||||
|
import {useI18n} from 'vue-i18n'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
modelValue: {
|
modelValue: {
|
||||||
|
@ -70,6 +82,8 @@ const props = defineProps({
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const {t} = useI18n()
|
||||||
|
|
||||||
const emit = defineEmits(['update:modelValue', 'change'])
|
const emit = defineEmits(['update:modelValue', 'change'])
|
||||||
|
|
||||||
const task = ref<TaskModel>()
|
const task = ref<TaskModel>()
|
||||||
|
@ -93,14 +107,19 @@ function updateData() {
|
||||||
if (task.value.repeatMode !== repeatModes.REPEAT_MODE_DEFAULT && repeatAfter.amount === 0) {
|
if (task.value.repeatMode !== repeatModes.REPEAT_MODE_DEFAULT && repeatAfter.amount === 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (repeatAfter.amount < 0) {
|
||||||
|
error({message: t('task.repeat.invalidAmount')})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
Object.assign(task.value.repeatAfter, repeatAfter)
|
Object.assign(task.value.repeatAfter, repeatAfter)
|
||||||
emit('update:modelValue', task.value)
|
emit('update:modelValue', task.value)
|
||||||
emit('change')
|
emit('change')
|
||||||
}
|
}
|
||||||
|
|
||||||
function setRepeatAfter(amount: number, type) {
|
function setRepeatAfter(amount: number, type) {
|
||||||
Object.assign(repeatAfter, { amount, type})
|
Object.assign(repeatAfter, {amount, type})
|
||||||
updateData()
|
updateData()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -783,7 +783,8 @@
|
||||||
"days": "Days",
|
"days": "Days",
|
||||||
"weeks": "Weeks",
|
"weeks": "Weeks",
|
||||||
"months": "Months",
|
"months": "Months",
|
||||||
"years": "Years"
|
"years": "Years",
|
||||||
|
"invalidAmount": "Please enter more than 0."
|
||||||
},
|
},
|
||||||
"quickAddMagic": {
|
"quickAddMagic": {
|
||||||
"hint": "You can use Quick Add Magic",
|
"hint": "You can use Quick Add Magic",
|
||||||
|
|
Loading…
Reference in a new issue