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

    Form Validation

    Framework
    3
    9
    8064
    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.
    • M
      maxant last edited by

      Are there any directives or similar so that I can define validation in the template rather than by using the validate object? E.g.:

      <q-input
          ...
          required
          maxlength="40"
          ...
          >
      

      Yeah, they are also Html5 validation attributes: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation#Validation-related_attributes
      I’m using Vuelidate, but if there is anything else out there I’d be happy to take a look.

      1 Reply Last reply Reply Quote 0
      • metalsadman
        metalsadman last edited by

        @maxant see quasar’s internal validations https://v1.quasar-framework.org/vue-components/input#Validation.

        1 Reply Last reply Reply Quote 0
        • M
          mKomo last edited by

          Quasars internal form validation should be good for most cases, however check out Vuelidate if you need more punch

          1 Reply Last reply Reply Quote 0
          • metalsadman
            metalsadman last edited by metalsadman

            he is already using Vuelidate though. @maxant try looking into Vee-Validate https://baianat.github.io/vee-validate/. It’s a template based validation library if quasar’s internal one is not enough in your case.

            1 Reply Last reply Reply Quote 0
            • M
              maxant last edited by maxant

              Thanks @metalsadman , @mKomo

              I took a look at the internal validation yesterday. I really like it, as it’s much simpler than Vuelidate.

              But I can’t find any docs on how to test it. E.g. I noticed that I can create a ref to a q-input and then access Validation stuff like this:

              this.$refs.other.validate()
              //false
              this.$refs.other.validateIndex
              //2
              

              I could also iterate over the rules and execute them myself to check that they are firing:

              this.$refs.other.rules[0](this.$refs.other.value)
              //true
              this.$refs.other.rules[1](this.$refs.other.value)
              //"Please use maximum 1 character" 
              

              But can I get the q-input to tell me which validation error it is currently showing? I guess the index above tells me that? Couldn’t find any docs though 😞

              1 Reply Last reply Reply Quote 1
              • metalsadman
                metalsadman last edited by metalsadman

                What test you are trying to do though? here’s their testing docs https://testing.quasar-framework.org/. probably take a look into vue js testing utils too https://vue-test-utils.vuejs.org.

                1 Reply Last reply Reply Quote 0
                • M
                  maxant last edited by

                  @metalsadman a “component test” with the goal of testing the component by interacting with it like a user would, as shown here: https://vue-test-utils.vuejs.org/guides/getting-started.html

                  1. mount the component
                  2. check its initial state (eg. that a part of the form containing details is closed)
                  3. click the button which opens the details
                  4. check the details widgets are present
                  5. enter some invalid data
                  6. check the relevant error messages are being “displayed” (the component isnt actually visible during these tests)
                  7. correct the problems
                  8. click the submit button
                  9. verify that the correct function is called

                  Nothing special really, just a standard “integration” test which checks the component works as designed.

                  1 Reply Last reply Reply Quote 0
                  • M
                    maxant last edited by

                    document.getElementById("claims-form-other").__vue__.validateIndex
                    

                    That number just increases every time validation is carried out. It is not the index of the validation rule which is currently being show.

                    1 Reply Last reply Reply Quote 0
                    • M
                      maxant last edited by

                      Internal validation error messages can be found like this during testing:

                      assert.equal(wrapper.vm.$refs.summary.innerErrorMessage, "Please use maximum 20 character", "focused on create button, so error on summary field is now shown")
                      

                      See https://forum.quasar-framework.org/topic/3437/unit-testing-and-simulating-input for more details.

                      API can be found here: https://v1.quasar-framework.org/vue-components/input#QInput-API

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