Trigger the Input event on Android with Nuxt

A unique issue has arisen with an input field that filters a list whenever a key is pressed, displaying the filtered results in the browser. While the functionality works perfectly on desktop, it behaves strangely on Android mobiles. The list only shows up after hitting the space or enter key. Even more peculiar is the fact that once space or "enter" is pressed on the Android keyboard, the list filters and displays correctly as you type. I have attempted using @keydown, @keyup, and @keypress events, but haven't achieved the desired behavior yet.

The Input Field with v-model

 <input
          v-model="searchValue"
          type="text"
          @input="filterStories"
        />

Filter Function and Data Properties

  data() {
    return {
      searchValue: '',
      filteredStories: []
  }
},
    methods: {
    filterStories() {
      if (this.stories.length) {
        let filtered = this.stories.filter(
          (story) =>
            story.name.toLowerCase().includes(this.searchValue.toLowerCase())
        )

        if (!this.searchValue) {
          this.filteredStories = []
        } else {
          this.filteredStories = filtered
        }
      }
    }

Output list in browser

       <li
          v-for="(story, i) in filteredStories"
          v-else-if="
            stories.length && filteredStories.length && searchValue
          "
          :key="i"
        >
          <NuxtLink
            :to="'/' + story.full_slug"
          >
            {{ story.name }}
          </NuxtLink>
        </li>

This detailed explanation should provide enough insight into the issue at hand. Thank you for looking into it!

Answer №1

When working with languages that require an IME (such as Chinese, Japanese, Korean, etc.), you may notice that v-model does not update during IME composition. In order to handle these updates, it is recommended to use the input event instead.

If v-model does not work with all types of keyboards, consider using value and @input instead of v-model:

<input
   :value="searchValue"
   type="text"
   @input="filterStories"
/>

Within the filterStory method:

filterStories(e) {
      this.searchValue = e.target.value
      if (this.stories.length) {
        let filtered = this.stories.filter(
          (story) =>
            story.name.toLowerCase().includes(this.searchValue.toLowerCase())
        )

        if (!this.searchValue) {
          this.filteredStories = []
        } else {
          this.filteredStories = filtered
        }
      }
}

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

Turn off Chrome Autofill feature when placeholders are being used in forms

I am encountering difficulties with Google autofill for fields that have placeholders. Despite attempting various solutions provided at: Disabling Chrome Autofill, none of them seem to work as needed. The challenge is to create a form with different field ...

What is the best way to utilize a component function within Vue to delete an item from an array stored in the parent's data?

It might be more helpful for you to take a look at the VueJS code related to this and then I can provide some explanation: new Vue({ el: '#app', data: { history: [ {name: 'red', value: '#f00'}, ...

code for handling window.location.href error

Continuing from the previous question, I am facing an issue with redirecting a form to an action while using Ajax. Despite my attempts to add a redirect in the Ajax function, I keep encountering errors and getting the wrong URL. The desired redirection is ...

What is the reason behind the non-reversible nature of atob and btoa

Looking for a simple way to obscure answers to quiz questions in Markdown temporarily? The idea is to reveal the answers during the presentation, no need for secure encryption. Considered using atob('message I want to obfuscate') and letting stu ...

Ensuring that the text box only accepts the letters A, B, and C is essential for

Could you please help me with validating a text box? I would like to set it so that the user can only enter either A, B, or C. If they input D to Z or any other characters, I want a popup message to appear asking them to Enter A, B, or C. Would you recom ...

What causes the transformation of [{"value":"tag1"} into [object Object] when it is logged?

Currently on my node.js server, the code I'm using is as follows: var tags = [{"value":"tag1"},{"value":"tag2"}]; console.log("tags: " + tags); My expectation was to see this in the console: tags: [{"value":"tag1"},{"value":"tag2"}] However, what ...

[Vuetify alert]: The server-side rendered virtual DOM structure does not align with the client-side content (Nuxt, Vue, and lerna monorepo)

I am currently facing an issue while attempting to run a basic Nuxt application within a lerna monorepo, which includes an external Vue component constructed using vue-cli. Initially, the page displays the content of the component (rendered by the server) ...

Combining Vue's v-model with :value for maximum control

Currently, I am facing an issue where I can only send the input value to the database instead of the selected image value. It is essential for me to have the selected image value sent to the database. This requires using v-model and :value simultaneously ...

Utilize React to update the state of arrays in functional components

Need help with updating the cars array in my React app. When I click on the Add button, a new object is added to the updatedCars array but the state of cars does not get updated. Even after adding a new object to the array, the initial state remains uncha ...

A-Frame's video and video sphere functionalities do not function properly on mobile and tablet devices

When using A-Frame, I've encountered issues with video and video sphere not auto playing. This is because mobile browsers typically require a user action to initiate video playback. I've tried implementing a click event to play the video, but it ...

Using Jquery to iterate through a dynamic list of elements

Currently, I am exploring the idea of creating a forEach loop that can handle an unspecified number of elements. The goal is to randomly select one element, perform XYZ actions on it, make it visible, and then eliminate it from consideration. This process ...

Include a new route in the Vue.js router dynamically during runtime

I am in the process of developing an application and I want to incorporate extensions into it. These extensions will have their own Vue components, views, and routes. Instead of rebuilding the entire app, I am looking for a way to dynamically add these new ...

Detect changes in class properties using Node.js

Is it feasible to establish direct proxy watchers for class properties in Node.js? class User{ constructor(name){ this.name = name; let pObject = new Proxy(this,{ set: () => { console.log("something cha ...

I am having trouble displaying SASS styles in the browser after running webpack with node

In my current project for an online course, I am utilizing sass to style everything. The compilation process completes successfully without any errors, but unfortunately, the browser does not display any of the styles. The styles folder contains five file ...

What is the best way to eliminate all instances of the period symbol from an array?

How can I eliminate all instances of . from my array? var arr = ['...my name is apple', 'my girl .... friend is banana.......']; Below is the code snippet I am currently using. var arr = ['...my name is apple', 'my g ...

Leveraging Mermaid for angular applications

As a newcomer to Mermaid, I am attempting to integrate it into my Angular project. Placing it in my HTML has proven successful. <script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/9.0.1/mermaid.min.js"></script> <div class="merma ...

Can you explain the distinction between using angular.copy() and simply using an assignment (=) to assign values

When a button is clicked, I want to assign certain values using the event parameter. Here is the code: $scope.update = function(context) { $scope.master = context; }; The $scope.master has been assigned the values of user. Recently, I came across th ...

Trim the final digits from the arrays

I have an array that contains various strings: var arr = ['1234','23C','456','356778', '56'] My goal is to filter out array elements that are less than 3 characters or more than 4 characters. The resultin ...

Incorporating JavaScript to dynamically load an HTML page into an iframe

I am attempting to have each option load a unique page within a frame <!DOCTYPE html> <html> <head> <script> function selectCountry() { var mylist=document.getElementById("country"); document.getElementById("frame").src=mylist.opti ...

instructions for transferring image filenames to a database with the help of multer and express

While utilizing multer and express to upload a photo, everything appears to be functioning correctly. However, I am encountering issues with sending the image name to the mongoose database. The images are successfully uploaded to the upload directory. Alt ...