I have a form with a submit button that is disabled by default. How do I make it enabled by any changes, without setting up a watcher for each input or some other way??
The Vuex mapState is empty when the template is mounted or created, so I can not deep clone that and compare with deep-diff for instance.. (also I did read its bad practice to deep clone states into variables).
My button:
<v-btn color="green" @click="onUpdateProfile" :disabled="!anyInputsChanged" :loading="false">Save</v-btn>
My input fields:
<InputField
label="Förnamn"
v-model="first_name"
/>
<InputField
label="Efternamn"
v-model="last_name"
/>
My script
import { mapState } from 'vuex'
import { mapFields } from 'vuex-map-fields'
import FormCard from '@/components/FormCard.vue'
import InputField from '@/components/base_components/InputField.vue'
export default {
components: {
FormCard,
InputField,
},
data () {
return {
loading: true,
isDisabled: true,
}
},
computed: {
...mapState(['user', 'userProfile']),
...mapFields([
'userProfile.first_name',
'userProfile.last_name',
'userProfile.fortnox_data.api_key'
]),
},
watch: {
},
mounted: function() {
this.loading = false;
},
methods: {
onUpdateProfile () {
this.$store.dispatch('updateUserData', {
id: this.user.uid,
first_name: this.userProfile.first_name,
last_name: this.userProfile.last_name,
updated_at: new Date().toISOString(),
})
},
}
}
the "anyInputsChanged" variable / computed / whatever I have not defined because I do not know how to. And bascially thats my question.. I want to enable "Submit" if any input element has changed, and disable if they all are unchanged.