Is there an issue with Vue 3's v-model not updating correctly in Chrome on Android devices?

In my project, I have developed a unique component that functions as a combination of an input and select field. This allows users to input text into the field and select items from a dropdown menu based on their query.

The component works flawlessly on most devices I've tested it on. As the user types in the input field, the list of items updates dynamically to show only those items that contain the typed string.

However, I recently encountered a strange issue with the Chrome browser on my Android device. The list does not update as I type unless I press the "space bar." Has anyone experienced this before or have any insights into why this might be happening?

Below is the code snippet inside the <script setup> tag:

const props = defineProps([ 'items', 'searchBy' ])
const searchTerm = ref('')

const itemsToShow = computed(() => {
    if (props.items) {
      if (searchTerm.value) {
        return props.items.filter(el => {
          if (props.searchBy) {
            return el[props.searchBy].toUpperCase().indexOf(searchTerm.value.toUpperCase()) > -1  
          }

          return el.toUpperCase().indexOf(searchTerm.value.toUpperCase()) > -1
        })
      } else {
        return props.items
      }
    } else {
      return []
    }
})

Here is the corresponding HTML code:

    <input 
      type="text" 
      class="input"
      v-model="searchTerm"
      placeholder=" " 
    />
    <div class="items-list">
      <div 
        v-for="item in itemsToShow" 
        :key="item" 
        @click="() => handleAdd(item)" 
        class="item text"
      >
        {{ item }}
      </div>
      <div 
        v-if="!itemsToShow.length" 
        class="text"
      >
        No items match searched term
      </div>
    </div>

UPDATE:

After some investigation, it appears that the binding between the searchTerm reference and the input field is not updating properly even though I used v-model. I am still puzzled by this behavior and not sure what could be causing it.

Answer №1

I have encountered this same issue in the past.

It appears that some devices require the v-model to wait for a change event rather than an input event.

This behavior seems to be related to the input method editor (IME) of the specific device.

You can find more information about this in a discussion on https://github.com/vuejs/core/issues/5580

To work around this, simply bind the input field using value and manually listen for the input event, for example:

<input 
  type="text" 
  class="input"
  :value="searchTerm"
  @input="(e) => searchTerm = e.target.value"
  placeholder=" " 
/>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Fixing VueJS axios issue: receiving 401 error for unauthorized POST request

I am having trouble sending a POST request with authorization to my REST api. Despite having CORS enabled on the server and everything working fine in Postman, I keep receiving an "unauthorized" error. Here is the code snippet I am using: axios . ...

What is the best way to combine two arrays containing objects?

I currently have two arrays containing objects: let employees = [ { name: 'Jason', job_id: '101' }, { name: 'Sarah', job_id: '102' }, { name: 'Jack', job_id: '102' } ] let jobs = [ { job_ ...

CSS tooltip within the document styling

Previously, I utilized the following code: I am seeking guidance on how to position the tooltip inline (to the right) with the parent div instead of above. Thank you for reviewing For a more user-friendly version, refer to this jsFiddle link HTML: < ...

Unveiling the steps to automatically conceal a submitted form in React, no longer requiring the manual activation of a toggle button

Currently, I have a list of songs and a toggle button that reveals a form to add a new song. However, I want the form to hide automatically after submission without requiring another button click. I tried using useEffect but couldn't get it to work. A ...

Performing an AJAX call every half-hour using JavaScript

I am looking to implement an ajax request every 30 minutes using JavaScript. Specifically, for the user currently logged in, I aim to retrieve any notifications that have a start date matching the current time. These notifications are set by the user with ...

"What is the purpose of using the `position: absolute` property for movement transitions while deleting an item from a list

Click here to see an example where items smoothly move in a list when one item is removed. To achieve this effect, the element needs to be styled with: .list-complete-leave-active { position: absolute; } I'm curious as to why it doesn't work w ...

How can I properly initialize React components?

I am currently learning React.js and experimenting with a progress bar animation. I stumbled upon this code that I would like to incorporate into my project, but I am unsure of where to place it. Check out the code here! The JavaScript code in question i ...

Swinging text using Javascript/JQuery on the edges of a container

I am looking to create a bouncing text effect within a specific div element (#header). The text successfully bounces off the right side, then reverses and hits the left side. However, the issue arises when it reaches the left side and begins moving right a ...

Creating a Pyraminx using triangular shapes

Attempting to create a Pyraminx, a tetrahedron made up of multiple triangles, through my coding. The approach I am taking may not be very precise. You can find my code here: https://codepen.io/jeffprod/pen/XWbBZLN. The issue I'm facing is manually in ...

Utilizing the power of JQuery's each() function alongside UI.sortable() for enhanced

Need help with updating data-priority attribute after sorting an unordered list using jQuery ui. Currently, the attribute is only set on load and not updated after each sort. I have created a fiddle to demonstrate the issue. It seems like a simple fix but ...

Dynamic Search Functionality using Ajax and JavaScript

function fetchData(str) { if (str.length == 0) { var target = document.querySelectorAll("#delete"); return; } else { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && ...

Remove array element by key (not numerical index but string key)

Here is a JavaScript array that I am working with: [#ad: Array[0]] #ad: Array[0] #image_upload: Array[0] 13b7afb8b11644e17569bd2efb571b10: "This is an error" 69553926a7783c27f7c18eff55cbd429: "Yet another error" ...

The div containing the AJAX POST success message suddenly vanishes within moments of being uploaded

Encountering an issue following a successful AJAX post, where the updated div disappears shortly after Here are the jquery/PHP/POST data in sequence. Button On Click Function: function Delete_ID(clickBtnValue,clickBtnID,clickBtnName) { var my_data = {& ...

Webpack is throwing an error due to the Vue component type being labeled as "any"

When using ts 4.2.4 and Vue3, I encountered a strange error while building my vue project: > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3a2a7aeaaededb3a2a0a083f3edf2edf3">[email protected]</a> build > v ...

Is it possible to access an external JavaScript file in the main.js by importing it?

In this scenario, I have defined an array of countries in an external Javascript file. const countries = [ "Australia", "Brazil", "China", "Denmark", "Egypt", "France", "Germany", "Hungary", "Italy", "Japan", ...

retrieve the value of an HTML element once it has been modified

When I am working in a view, I encounter an issue where I need to retrieve the value of an HTML input box after it has been changed. Initially, the page loads with the following code: <input id="input_one" type="text" value = "apple" /> Upon loadin ...

Error message: Unable to locate module without the '.js' extension at the end of the import file path

It seems like the solution is not difficult, just something obvious. I am working on a simple TypeScript project. There are no modules involved, only TypeScript for compilation. The TS files compile into JS files in the dist folder, which are then connect ...

Integrate hash filtering for external links using a custom solution similar to Isotope

Illustration: When a user clicks on a specific link within a webpage, they will be redirected to tailored content in a designated section. I attempted to create a custom isotope using basic hide and show classes, but I am facing difficulty connecting ...

What is the best way to update the image card in bootstrap?

Could someone please assist me in changing the image displayed? I keep getting the same copied image, but I would like id 1 to have a different image. This is crucial as I plan to present this for my defense in class. Thank you. let htmlString = ` <di ...

Utilize jQuery in phantom.js to send an ajax request across domains

I am currently in the process of testing a chrome plugin by emulating a portion of its functionality on phantomjs. My objective for phantom seems quite straightforward, yet I am encountering issues. I aim for it to navigate to a specific webpage and withi ...