No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Can I use q-input rules with a template variable

    Help
    2
    2
    1672
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • yk-davdomin
      yk-davdomin last edited by

      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>
      
      
      1 Reply Last reply Reply Quote 0
      • D
        dmoylan last edited by

        (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.

        1 Reply Last reply Reply Quote 1
        • First post
          Last post