I have this computed property.
import { mapState } from 'vuex'
export default {
computed: {
...mapState('user/requestAcc', ['AccountValidation', 'selectedWorkload','AccountOnboarding','Regions','customers']),
validatedForSubmission() {
if(this.type !== 'Internal'){
if (this.AccountValidation.wbsType === 'WBSCode1') {
if(this.type !== 'New'){
return !this.AccountValidation.agreed || !this.AccountValidation.wbsCodeValidated || !this.AccountValidation.iwoCodeValidated
} else {
return !this.AccountValidation.agreed || !this.AccountValidation.wbsCodeValidated
|| !this.awsAccountValidation.iwoCodeValidated || !this.AccountOnboarding.fields.Tmp_Cust_Name ||!this.AccountOnboarding.fields.Cust_Region || !this.AccountOnboarding.fields.Customer_Alias || this.errors.items.length
}
} else {
if(this.type !== 'New'){
return !this.AccountValidation.agreed || !this.AccountValidation.wbsCodeValidated
} else {
return !this.AccountValidation.agreed || !this.AccountValidation.wbsCodeValidated
|| this.AccountOnboarding.fields.Tmp_Cust_Name === '' ||!this. AccountOnboarding.fields.Cust_Region || !this.AccountOnboarding.fields.Customer_Alias || this.errors.items.length
}
}
} else {
if (this.AccountValidation.wbsType === 'WBSCode1') {
return !this.AccountValidation.wbsCodeValidated || !this.AccountValidation.iwoCodeValidated
} else {
return !this.AccountValidation.wbsCodeValidated
}
}
}
}
The computed property is linked to :disabled in a v-btn. So if the computed property returns a false value, it would enable(remove disabled) the v-btn.
<v-btn :disabled='validatedForSubmission' color="warning" @click='onAcctValidationSubmit'>Next</v-btn>
I connected one of the object properties from AccountOnboarding in a v-text-field. This is a reactive dependency in the validatedForSubmission computed property.
<v-text-field
placeholder="Customer_Alias"
:counter="15"
v-model="AccountOnboarding.fields.Customer_Alias"
v-validate="'required'"
data-vv-name="Customer Alias"
:error-messages="errors.collect('Customer Alias')"
outlined
dense
>
</v-text-field>
I have method linked to a v-autocomplete. This method checks if there is an existing Customer Registration.
methods: {
getCustomerRegion() {
let custAlias = this.AccountOnboarding.fields.Customer_Alias
let custName = this.AccountOnboarding.fields.Tmp_Cust_Name
let custReg = this.AccountOnboarding.fields.Cust_Region
let isCustRegExist = this.customers.filter(res => res.Cust_Region.includes(custName+' - '+custReg))
if(isCustRegExist.length > 0) {
this.AccountOnboarding.isCustRegion = true
let alias = isCustRegExist[0].Customer_Alias
this.AccountOnboarding.fields.MP_ID = isCustRegExist[0].Master_Id
console.log('1. -------- selected customer --------')
console.log('2. alias: ' + alias)
console.log('3. -----------------------------------')
if (alias !== 'None'){
this.AccountOnboarding.custRegion =''
this.AccountOnboarding.custRegionId= isCustRegExist[0].Customer_Id
this.AccountOnboarding.fields.Customer_Alias = isCustRegExist[0].Customer_Alias
this.$store.commit('user/requestAcc/setCustomerAlias', alias)
} else {
console.log('customer update...')
this.AccountOnboarding.custRegionAction = 'update'
this.AccountOnboarding.custRegionId = isCustRegExist[0].Customer_Id
this.AccountOnboarding.fields.Customer_Alias =''
this.$store.commit('user/requestAcc/setCustomerAlias', this.AccountOnboarding.fields.Customer_Alias)
}
} else {
console.log('customer create...')
this.AccountOnboarding.fields.Customer_Alias =''
this.AccountOnboarding.custRegionAction = 'post'
this.AccountOnboarding.isCustRegion = false
this.AccountOnboarding.custRegionId = ''
let alias = this.AccountOnboarding.fields.Customer_Alias
this.$store.commit('user/requestAcc/setCustomerAlias', alias)
}
}
<v-autocomplete
v-model="AccountOnboarding.fields.Cust_Region"
:items="Regions"
placeholder="Select Customer Region"
v-validate="'required'"
data-vv-name="Customer Region"
data-vv-validate-on="blur"
:error-messages="errors.collect('Customer Region')"
@change = "getCustomerRegion"
attach
outlined
dense
>
</v-autocomplete>
The computed property works fine and enables the button when there is an existing customer registration and it has a customer alias (which fills up the v-text-field). However, for new registrations or existing customers with no alias, you can see that the method would set *this.AccountOnboarding.fields.Customer_Alias =” * and once you type in an alias in the v-text-field where you linked the AccountOnboarding.fields.Customer_Alias as a v-model, it does show that the AccountOnboarding.fields.Customer_Alias contains the inputted value but the computed property does not recalculate it even though it is a reactive dependency. Leading to the computed property to return false even if the conditions are met.
I have tried removing the code this.AccountOnboarding.fields.Customer_Alias =” for both customer update and customer create conditions in the getCustomerRegion method, it worked but I do not want to remove the code.