So, I have data with multiple objects like so:
let form = {
name: '',
bank: {
name: '',
number: '',
}
}
data: form,
errors: JSON.parse(JSON.stringify(form))
When an error occurs (a value is empty, it gets added to the errors property, so, if the name is empty, the errors will be like
errors: {
name: {
{'Name must be set'}
}
}
Now, as you can see, because the bank object never got an error, the errors property won't have a bank object, which causes error (I can't return empty data for banking, so need a way in my html)
So, in my html, I am trying to get the errors from the errors property
<input type="text"
class="bg-grey-lightest border outline-none p-2 text-black text-sm w-full"
placeholder="{{ __('ex : Barclays') }}"
v-model="form.bank.bank">
<span v-for="error in errors.bank.bank" class="hasError">
@{{ error }}
</span>
The html above throws an error, because errors.bank.bank doesn't exists, only errors.name as explained above, so how can I check that object exists before running it through the v-for to get the errors?