I'm currently using Vuetify form validation to validate an input field, and I'm exploring the possibility of making an ajax get call await so that I can utilize the result in a rule. However, my attempts at this approach have not been successful!
export default {
data() {
return {
rules: {
isLocationNew: value => {
if (value == '' || value == null || value.length <= 1) {
this.validLocation = false;
return 'Invalid length.';
}
this.validLocation = true;
var hasName = this.checkDuplicateLocation(value);
if (hasName) {
return 'Location name already exists.';
} else {
return true;
}
}
},
// Defined method below
methods: {
async checkDuplicateLocation(text) {
if (text == '' || text == null || text.length <= 1) {
return false;
}
let response = await axios.get('/api/Locations/HasLocationName', {
params: {
text: text,
jobsiteId: this.jobsiteId
}
});
return response.data;
}
}