I am using Quasar to build my Vue app.
It comes with form validation baked in through the use of the :rules prop.
Example 1 (inline):
<q-input
ref="inputRef"
filled
v-model="model"
label="Required Field"
:rules="[val => !!val || 'Field is required']"
/>
Example 2 (rule extracted to a varible):
<template>
<q-input
ref="inputRef"
filled
v-model="model"
label="Required Field"
:rules="emailRules"
/>
</template>
<script setup>
const emailRules = val => !!val || 'Field is required';
</script>
But instead of writing out my own rule schema (and possibly missing lots of edge cases) I want to use the popular Yup validation schema library.
So how do I combine Yup with these Quasar rules?
I was thinking I could do something like this:
<template>
<q-input
ref="inputRef"
filled
v-model="model"
label="Required Field"
:rules="emailRules"
/>
</template>
<script>
import * as yup from 'yup';
const emailSchema = yup.string().email();
const emailRules = [(val) => await emailSchema.isValid(val) || 'Access the Yup error message here somehow??' ];
</script>
But I don't know how to access the default error message returned by Yup and use it in the second half of the rule.