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

    Pattern property for q-input

    Help
    6
    8
    3575
    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.
    • P
      pavarine last edited by

      I’m trying to add a ‘pattern’ property in a QInput. I want no numbers/digits to be allowed in this field. What am I missing?

            <q-input  v-model="cur_agent.name" pattern="[a-zA-z]*" float-label="Nome" placeholder="Nome"/>
      s.molinari 1 Reply Last reply Reply Quote 0
      • s.molinari
        s.molinari @pavarine last edited by s.molinari

        Your missing reading the docs. :face_with_stuck-out_tongue_winking_eye:

        Seriously though. There is no such thing as a pattern prop. If you are going to be working more intensely with form inputs, you might want to think about using Vuelidate.

        https://monterail.github.io/vuelidate/#sub-builtin-validators

        If vuelidate is too much for your use case, you can build your own filter.

        https://vuejs.org/v2/guide/filters.html

        Scott

        P 1 Reply Last reply Reply Quote 0
        • P
          pavarine @s.molinari last edited by

          @s-molinari Believe me, I did read the docs. That’s just why I thought it could work, cause of this section (from docs):

          IMPORTANT
          All DOM attributes that apply to a native <input> or <textarea> can be used. Example: maxlength, rows, min/max/step, autocomplete and so on.

          So I tought pattern would work.

          I tried vuelidate, but it will just warn me about the invalid fields and I want something that prevents me from inputing any text that dont match the pattern, like some type of input mask.

          But thanks anyway

          1 Reply Last reply Reply Quote 0
          • s.molinari
            s.molinari last edited by s.molinari

            Hmm… I see what you mean. Didn’t realize there is a pattern attribute and it doesn’t look like it works as an attribute.

            I came up with this. Not sure how robust it is. But, maybe it will help.

            https://jsfiddle.net/smolinari/d0e86tao/

            Scott

            1 Reply Last reply Reply Quote 0
            • R
              Recke last edited by

              I think to introducing patterns for inputs is very important to cover

              1 Reply Last reply Reply Quote 2
              • luckylooke
                luckylooke last edited by

                In current version you can use masks https://quasar.dev/vue-components/input#Mask but anyway I did not find the way to set custom group of allowed characters… lets say I want to input to accept only alfanumeric and dash “-” characters… I cannot achieve this via masks.

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

                  @luckylooke you can do it with a regexp in an @input handler. ie. <q-input v-model="model" @input="v => { model = v.replace(/[^0-9a-zA-Z-]/g,'') }" />.

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

                    @metalsadman, how could I extend this example to work as a mask, i.e. prevent invalid characters to show at all? The code <q-input v-model="model" @input="v => { model = v.replace(/[^0-9a-zA-Z-]/g,'') }" / does work, but only when the input loses focus.

                    Thanks!

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