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 get the Cursor Position form q-input?

    Framework
    2
    5
    1034
    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.
    • W
      wagner last edited by wagner

      I need access to the current cursor position in the q-input field the following code returns cursorPos: undefined on the console.

      This shows how to do it for a regular input field. Not sure why quasar is not exposing the input element.
      https://stackoverflow.com/a/48149119/11314311

      What is the correct way to do this?

      <q-input v-model="input" ref="inputval" @input="changeInput" />
      
      changeInput(value) {
         if (this.$refs.inputval) {
            this.cursorPosition = this.$refs.inputval.selectionStart;
            console.log('cursorPos:', this.cursorPosition)
        }
        this.cursorPosition = 0;
      },
      
      1 Reply Last reply Reply Quote 0
      • metalsadman
        metalsadman last edited by metalsadman

        @wagner try this.$refs.inputval.$el.selectionStart notice the $el. or log your ref and see children elements, look for the input element, so you can select it using the children’s array.

        1 Reply Last reply Reply Quote 1
        • W
          wagner last edited by wagner

          Unfortunately, this.$refs.inputval.$el.selectionStart does not work either.

          This is the S section under this.$refs.inputval.$el when I log it to the console.

          prefix: null
          previousElementSibling: p.instructmsg
          previousSibling: p.instructmsg
          scrollHeight: 76
          scrollLeft: 0
          scrollTop: 0
          scrollWidth: 496
          shadowRoot: null
          slot: ""
          spellcheck: true
          style: CSSStyleDeclaration {alignContent: "", alignItems: "", alignSelf: "", alignmentBaseline: "", all: "", …}
          tabIndex: -1
          tagName: "DIV"
          textContent: ""
          title: ""
          translate: true
          
          metalsadman 1 Reply Last reply Reply Quote 0
          • metalsadman
            metalsadman @wagner last edited by metalsadman

            @wagner here https://codepen.io/metalsadman/pen/VwwVMaK?&editable=true&editors=101, basically you want to tap into the actual input element wrapped by QInput. logging the refs will give you hint, I got it that way in the browser console log.

            1 Reply Last reply Reply Quote 1
            • W
              wagner last edited by

              This works. Thank you.

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