Can I use q-input rules with a template variable
-
Hi guys
I am a noob usinhg quasar - vueJS and I need to validate a q-input with a template variable but don’t work…
Is this possible?
I did a sandbox with a little example:https://codesandbox.io/s/blissful-meadow-e64gh?file=/src/pages/Index.vue
<template> <q-page class="flex flex-center"> <q-form class="q-gutter-md"> <q-input v-model="text1" label="text1" :rules="[ (val) => !!val || 'This field is required', (val) => !falgs.flag1 || 'The flag1 must be activaed' ]" > </q-input> <q-input v-model="text2" label="text2" :rules="[(val) => !!val || 'This field is required']" > </q-input> </q-form> </q-page> </template> <script> export default { name: 'PageIndex', data() { return { text1: '', text2: '', flags: { flag1: false, flag2: false } } } } </script>
-
(val) => flags.flag1 || ‘The flag1 must be activated’
Pretty sure this is what you are going for right? You misspelled flags (and “activated”, btw), and putting !flags means that you satisfy the validation condition when flag1 is false.