improve logic and date handling. use v-model for form

This commit is contained in:
Moriz Wahl 2022-07-15 11:23:03 +02:00
parent 9efb83b2af
commit 66f10df1d0
2 changed files with 7 additions and 19 deletions

View File

@ -12,7 +12,6 @@
<b>{{ $t('contribution.formText.text2') }}</b>
</div>
</div>
{{ id }}
<b-form ref="form" @submit.prevent="submit">
<label>{{ $t('time.month') }}</label>
<b-form-datepicker
@ -66,21 +65,14 @@
export default {
name: 'ContributionForm',
props: {
id: { type: Number, required: false, default: null },
date: { type: String, required: false },
memo: { type: String, required: false },
amount: { type: String, required: false },
value: { type: Object, required: true },
},
data() {
return {
minlength: 50,
maxlength: 255,
max: new Date(),
form: {
date: this.id === null ? '' : this.date,
memo: this.id === null ? '' : this.memo,
amount: this.id === null ? '' : this.amount,
},
form: this.value,
}
},
methods: {
@ -97,10 +89,10 @@ export default {
*
*/
lastMonth() {
return new Date(new Date(new Date().setMonth(new Date().getMonth() - 1)))
return new Date(this.max.getFullYear(), this.max.getMonth() - 1, 1)
},
min() {
return new Date(new Date(new Date().setMonth(new Date().getMonth() - 1)).setDate(1))
return new Date(this.max.getFullYear(), this.max.getMonth() - 1, 1)
},
disabled() {
if (
@ -127,10 +119,5 @@ export default {
return this.$t('contribution.formText.thisMonth', obj)
},
},
watch: {
id(newId, oldId) {
alert('eine id kommt mit')
},
},
}
</script>

View File

@ -3,7 +3,7 @@
<div>
<b-tabs v-model="tabIndex" content-class="mt-3" align="center">
<b-tab :title="$t('community.writing')" active>
<contribution-form @set-contribution="setContribution" v-bind="form" />
<contribution-form @set-contribution="setContribution" v-model="form" />
</b-tab>
<b-tab :title="$t('community.myContributions')">
<contribution-list
@ -113,10 +113,11 @@ export default {
})
},
updateContribution(item) {
this.tabIndex = 0
this.form.id = item.id
this.form.date = item.createdAt
this.form.memo = item.memo
this.form.amount = item.amount
this.tabIndex = 0
},
updateTransactions(pagination) {
this.$emit('update-transactions', pagination)