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

    How to UpperCase v-model of q-input?

    Help
    4
    14
    5094
    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
      marconi last edited by

      I am creating a directive for this.

      export default ({ Vue }) => {
          Vue.directive('uppercase', {
              update (el, binding, vnode) {
                  el.value = el.value.toUpperCase()
              }
          })
      }
      

      I’m using:

      <q-input
                          v-model="contato.nome"
                          class="text-uppercase"
                          dense
                          type="text"
                          outlined
                          placeholder="Nome"
                          float-label="Nome"
                          @blur="$v.contato.nome.$touch"
                          :error="$v.contato.nome.$error"
                          v-uppercase/>
      

      But my element is not an input, console.log (el) return:

      8c261124-276c-4a7f-9dcd-ea77221d131a-image.png

      Console erro:

      Cannot read property ‘toUpperCase’ of undefined

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

        I think you have to query the correct element in the el tree.
        el.getElementsByTagName(‘input’)[0].value = el.getElementsByTagName(‘input’)[0].value.toUpperCase();

        M 1 Reply Last reply Reply Quote 0
        • M
          marconi @arlecchino last edited by

          @arlecchino Not work 😞

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

            This is a quick way. There are other methods, like creating a filter or a directive.

            https://codepen.io/smolinari/pen/VwwpZWO?editors=1010

            Scott

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

              @marconi you can do @input="v => { contato.nome = v.toUpperCase() }"

              M 1 Reply Last reply Reply Quote 1
              • M
                marconi @metalsadman last edited by marconi

                @metalsadman said in How to UpperCase v-model of q-input?:

                @input=“v => { contato.nome = v.toUpperCase() }”

                I need aply in all inputs. What can I do ?

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

                  @s-molinari
                  I need aply in all inputs. What can I do ?

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

                    @marconi you should make a wrapper with that setup and use it wherever, or see @s-molinari 's suggestions.

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

                      @metalsadman Ok, thanks for your reply, I am sorry for my english.

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

                        @marconi here you go using Vue.extend https://codepen.io/metalsadman/pen/eYYvNNG?editors=1010

                        M 1 Reply Last reply Reply Quote 1
                        • M
                          marconi @metalsadman last edited by

                          @metalsadman 🙂 , this is a beautiful code. Thanks, I will add in my project

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

                            @metalsadman How can I registry this component global?

                            I added extensions.js in boot

                            import Quasar from 'quasar'
                            export default ({ Vue }) => {
                                const CustomInput = Vue.extend({
                                    name: 'CustomInput',
                                    extends: Quasar.QInput,
                                    props: { upperCase: { type: Boolean, default: true } },
                                    watch: {
                                        value (v) {
                                            this.upperCase && this.$emit('input', v.toUpperCase())
                                        }
                                    }
                                })
                                Vue.component(CustomInput)
                            }
                            

                            Modified quasar.config.js

                                boot: [
                                    'i18n',
                                    'axios',
                                    'vuelidate',
                                    'auth',
                                    'extensions'
                                ],
                            

                            My input is empty

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

                              @marconi you have the idea of how to include it, just need some changes. should be import { QInput } from 'quasar', then just extends: QInput,, also provide a name in the Vue.component('CustomInput', CustomInput). then on your template you can just go <custom-input ... />. you can see it here https://0ybb3.sse.codesandbox.io/form-validations/external-vuelidate the bottom input.

                              full boot code:

                              import { QInput } from 'quasar'
                              
                              export default async ({ Vue }) => {
                                const CustomInput = Vue.extend({
                                  name: 'custom-input',
                                  extends: QInput,
                                  props: { upperCase: { type: Boolean, default: true } },
                                  watch: {
                                    value(v) {
                                      this.upperCase && v && this.$emit('input', v.toUpperCase()) // added a guard for value when it's null
                                    }
                                  }
                                })
                                Vue.component('CustomInput', CustomInput)
                              }
                              
                              M 1 Reply Last reply Reply Quote 2
                              • M
                                marconi @metalsadman last edited by

                                @metalsadman Good Job, thanks for help me.

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