Reputation: 31
I try to put class 'has-error' based on condtion and handle vaildation message for that v-select but i don't know how achieve that
<v-select
v-model="add.city"
:options="currentCities"
:label="$store.getters['GET_LANG_NAME'] === 'ar' ? 'nameAr' : 'nameEn'"
:placeholder="$t('addresses.addCity')"
required
class="select porder-radius-5 text-gray input_fixed-height"
:class="{ 'text-align-right': $store.getters['GET_LANG_NAME'] === 'ar' , 'has-error': errors.has('addAddressForm.city') }"
> </v-select>
I have tried to handle that using Scoped slot but nothing happen
<v-select
v-model="add.city"
:options="currentCities"
:label="$store.getters['GET_LANG_NAME'] === 'ar' ? 'nameAr' : 'nameEn'"
:placeholder="$t('addresses.addCity')"
required
class="select porder-radius-5 text-gray input_fixed-height"
:class="{ 'text-align-right': $store.getters['GET_LANG_NAME'] === 'ar' }"
>
<template #search="{ search, attrs, events }">
<input
type="search"
v-bind="attrs"
v-on="events"
class="vs__search"
:class="{ 'has-error': errors.has('addAddressForm.city') }"
/>
</template>
</v-select>
Upvotes: 1
Views: 74
Reputation: 1093
errors
is reactive. For example wrap it in reactive
:<script setup>
import { reactive } from 'vue'
const reactiveErrors = reactive(errors)
</script>
errors.has('addAddressForm.city')
:<script setup>
import { computed } from 'vue'
const errorClass = computed(() => reactiveErrors.has('addAddressForm.city'))
</script>
<template>
<input
:class="{ 'has-error': errorClass }"
/>
</template>
Upvotes: 0