I am working on a housing application that currently uses a datetime field for move in date and move in time. I don't really like how the datetime format looks on the frontend, but I want to keep it in my SQL database, so my idea on how to execute this was:
1: When page is loaded, split the datetime field into seperate date and time fields. 2: If the user make changes to the date or time and clicks "update", then the fields will be merged back into the datetime field.
I thought it would be simple, but when I try to do this, I get the error "Cannot set properties of null (setting '0')"
Here is a simplified version of my code. I am using Vue Bootstrap for this application.
<template>
<b-form-row>
<b-col lg="6">
<b-form-group :label="$t('Date and time')">
<date-time-picker
v-model="tenancy.moveInDate"
:format="format"
:show-second="false"
type="datetime"
/>
</b-form-group>
</b-col>
</b-form-row>
<b-form-row>
<b-col lg="6">
<b-form-group :label="$t('Move in date')">
<b-date-picker v-model="tenancy.date"/>
</b-form-group>
</b-col>
</b-form-row>
<b-form-row>
<b-col lg="6">
<b-form-group :label="$t('Move in time')">
<b-time-picker v-model="tenancy.time" />
</b-form-group>
</b-col>
</b-form-row>
</template>
export default {
data() {
return {
tenancy: {
moveInDate: moment('DD/MM/YYYY HH:mm'),
date: moment('DD/MM/YYYY'),
time: moment('HH:mm'),
}
}
},
computed: {
format() {
return localeOptions[this.$i18n.locale].datepicker.format + ' LT';
}
},
methods: {
update(){
this.tenancy.moveInDate[0] = this.tenancy.date;
this.tenancy.moveInDate[1] = this.tenancy.time;
}
},
created() {
this.tenancy.date = tenancy.moveInDate.split('')[0]
this.tenancy.time = tenancy.moveInDate.split('')[1]
}
}