Deactivate QInput rules if QInput is disabled.
-
Hi everyone from Chile!
Maybe someone could help me.
So I have this QForm and I have some social media q-input links where you have to click on a checkbox to enable the input before inputting your link.
On each input, I validate the input with a regex to make sure it contains “http” or “https” in it.The thing is, if i don’t enable the input, on submit If i validate the form it will validate also the “disabled” inputs that have no content.
Example:
<q-input square outlined ref="facebook" label="FACEBOOK" placeholder="https://wwww.facebook.com/username" class="q-pb-lg custom-field-checkbox" bg-color="white" v-model="data.facebook.link" :disable="!data.facebook.enable" :rules="[val => val.match(/^(http|https):\/\/(.*)/) || 'Incorrect Link format']" lazy-rules />
Where if “data.facebook.enable” is true, I would like to trigger the rules.
I know some workaround, but I wanted to know if there is an easier way to solve this. Also, add, this is a child component of the overall form.
Thanks in advance!
-
This was quickly solved by someone in Discord (Jeff Galbraith)
The solution was this one if anyone ever finds itself in the same seat:<q-input square outlined ref="youtube" label="YOUTUBE" class="q-pb-lg custom-field-checkbox" bg-color="white" v-model="data.youtube.link" :disable="!data.youtube.enable" :rules="[val => data.youtube.enable !== true ? true : val.match(/^(http|https):\/\/(.*)/) || 'Incorrect Link format']" lazy-rules />