What is the best way to customize the display of filtered options in my VueJA/Buefy autocomplete?

While using VueJS and Beufy for an autocomplete feature, I encountered a problem with the filtering mechanism. When I type in a description, the input box filters correctly (e.g. typing "ar" filters the options), but I am unable to see any selectable options. Even though the options are present (as evidenced by clicking on them), the data does not show up visually.

https://i.sstatic.net/kXhIz.png

Another issue that arises is upon selecting one of these invisible options, resulting in the following error:

vue:634 [Vue warn]: Error in render: "TypeError: Cannot read property 'toLowerCase' of undefined"

It seems that the descriptions are blank in the autocomplete, causing the error when trying to perform operations like toLowerCase() on non-existent values.

Could someone please point out what I might have overlooked?

Answer №1

After some trial and error, I finally found the missing piece that made this task harder than expected:

field="Description"

To make the autocomplete field work properly, you must specify the key from the object to use in the dropdown. In my case, it was "Description", so the correct code is:


<!DOCTYPE html>
<html>
<head>
  <title>Product Search Test</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://unpkg.com/buefy/dist/buefy.min.css">
</head>

<body>
    <div id="app">
      <div class="container">
        <b-field label="Find a Product">
            <b-autocomplete
                :data="filteredDataArray"
                v-model="item_entered"
                placeholder="e.g. SKU87128398"
                :loading="isFetching"
                field="Description"
                @select="option => (selected = option)">
            </b-autocomplete>
        </b-field>
      </div>

        {{selected}}


    </div>

    <script src="https://unpkg.com/vue"></script>
    <!-- Full bundle -->
    <script src="https://unpkg.com/buefy/dist/buefy.min.js"></script>

    <!-- Individual components -->
    <script src="https://unpkg.com/buefy/dist/components/table"></script>
    <script src="https://unpkg.com/buefy/dist/components/input"></script>

    <script>
        new Vue({
            el: '#app',
            data() {
                        return {
                            data: [],
                            selected: '',
                            isFetching: false,
                            item_entered: '',
                            initial_query: {
                                "message": "success",
                                "item_list": {
                                    "Items": [{
                                            "Description": "Marvel's Avengers",
                                            "Highlight": "PEGI Rating: Ages 12   and Over",
                                            "Id": "1118498",
                                            "Type": "Product"
                                        },
                                        {
                                            "Description": "LEGO Harry Potter Collection",
                                            "Highlight": "PEGI Rating: Ages 10 and Over",
                                            "Id": "28331719",
                                            "Type": "Product"
                                        },
                                        {
                                            "Description": "Star Wars Jedi: Fallen Order - Standard ",
                                            "Highlight": "PEGI Rating: Ages 10 and Over",
                                            "Id": "50510378",
                                            "Type": "Product"
                                        },
                                        {
                                            "Description": "Monster Hunter World Iceborne Master Edition",
                                            "Highlight": "PEGI Rating: Ages 12 and Over",
                                            "Id": "51580152",
                                            "Type": "Product"
                                        },
                                        {
                                            "Description": "High Street, Bruton - More Addresses",
                                            "Highlight": "PEGI Rating: Ages 18 and Over",
                                            "Id": "0AA-BA10",
                                            "Type": "Group"
                                        }
                                    ]
                                }
                            },
                        }
                    },
                    methods: {
                      getProductData: function(){

                      }
                    },
                    computed: {
                        filteredDataArray() {
                            return this.initial_query.item_list.Items.filter((option) => {
                              console.log(option.Description.toString().toLowerCase())
                              console.log(option
                                .Description
                                .toString()
                                .toLowerCase()
                                .indexOf(this.item_entered.toLowerCase()) >= 0)
                                return option
                                  .Description
                                  .toString()
                                  .toLowerCase()
                                  .indexOf(this.item_entered.toLowerCase()) >= 0
                            })
                        }
                    }
        })
    </script>
</body>
</html>

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

What is the best method to evaluate lambda functions in a functional React Component using Jest and Enzyme?

My current challenge involves creating a pulldown tab in a TDD style. I have been struggling to test if the function inside the component triggers on the button's click event. The jest logs keep showing me errors indicating that the object I'm tr ...

Activate UpdatePanel upon hovering the mouse cursor over it (displayed as a tooltip)

In order to provide users with additional information, such as a tooltip, on items within a RadioButtonList, I am looking to display about 500 - 600 characters of info. Currently, I am updating a PanelUpdate when a user selects an item in the RadioButton ...

What is the best way to place Vue chunk files into the public/js folder using Laravel Mix?

In my Laravel and Vue project, I am utilizing dynamic import function calls in Vue to separate my components into different files. While everything is functioning properly, I have noticed that the Vue chunk files (such as 0.js, 1.js, etc.) are being store ...

"MongoDB Reveals Its True Power: Unveiling the Second

I am facing an issue with the second res.json. I have attempted the following: res.json({500,message : 'xxxxxx'}) res.send({500,message : 'xxxxxx'}) However, the problem persists. Here is my code snippet: import mongoose from ' ...

Guide on incorporating Firebase "onSnapshot" listener values to update a Vue "ref" variable

I have implemented a Vue composable feature that utilizes a Firebase onSnapshot listener to track data changes. The goal is to update a ref called documentsArray whenever there is a change detected by the listener. Interestingly, when I log the contents ...

What is the best way to determine the number of queryClient instances that have been created?

Currently, I am managing a large project where the code utilizes useQueryClient in some sections to access the queryClient and in other sections, it uses new QueryClient(). This approach is necessary due to limitations such as being unable to invoke a Reac ...

What is the best way to receive a callback when a user cancels a dialog box to choose a mobile app after clicking on

I am currently exploring HTML coding for mobile devices and looking to integrate map routing functionality. When it comes to mobile devices, utilizing the local app is the more practical option, and I have had success implementing this by modifying the l ...

Guide for creating a function that accepts an array containing multiple arrays as input

I am working with a function called drawSnake and it is being invoked in the following manner: drawSnake( [ [0, 0], [0, 1], [0, 2], [0, 3], [0, 4], ] ); How should I format the input for this function? I have attempted using Array<Array<[numb ...

Disabling the smooth scrolling feature on tab navigation

I am using smooth scroll JS to navigate from a menu item to an anchor located further down the page. However, I am encountering an issue where my tabs (which utilize #tabname) also trigger the scroll behavior when clicked on. Is there a simple modificati ...

Retrieving vue-cli-version-marker from local source

Whenever I try running vue ui without administrative privileges, the following error occurs: Failed to receive a response from https://registry.npmjs.org/vue-cli-version-marker However, when run with admin rights, it works. This issue seems to be connecte ...

Utilizing the child's property of an object in Three.js beyond the loader.load function

I am looking for a way to dynamically update the color property of an object using dat.GUI(). It is straightforward when working with objects created using three.js geometry. However, I am facing some challenges as I am working with imported objects (.obj ...

Styling CSS variables uniquely

I have limited knowledge of HTML and CSS, so I am unsure how to search for a similar post on StackOverflow. My apologies if this is a duplicate question. I am looking to achieve the following: margin-horizontal { margin-left: value; margin-right: va ...

Accessing JSON data from a URL for use within a specific context

I am currently utilizing the request module within Express to fetch a JSON file from a specified link. var url = 'https://api.github.com/users/google/repos'; request.get({ url: url, json: true, headers: {'User-Agent': &apo ...

Are There Any Techniques for Adding Objects to an Array in a Unique Way?

Is there a simple way to add an object to an array in ES6 while ensuring it is unique? For example: MyArray.pushUniquely(x); Or is it better to stick with the older method like this? : MyMethod(x) { if ( MyArray.IndexOf(x) === -1 ) MyArra ...

Accept a JSON-sending POST request in a JSP file via JavaScript

I have developed an HTML page with an input field. Using javascript, I extract the input value, convert it into JSON format, and attempt to send it through ajax. Additionally, I have a JSP application where a Java method processes this JSON data to store i ...

The $.ajax method seems to be experiencing some issues, but fortunately, the $.getJSON

I'm in the process of retrieving the share count for Pinterest and the following code is functioning effectively: var pi_like_count = 0; PIUrl = "https://api.pinterest.com/v1/urls/count.json?url=" + url1 + "&format=jsonp" + '&callback=? ...

No errors detected when utilizing bcrypt-node for callbacks

I have developed a node library file named encrypt.js. Inside this file, there are functions created using bcrypt-nodejs var bcrypt = require('bcrypt-nodejs'); exports.cryptPassword = function(password, callback) { bcrypt.genSalt(10, f ...

Struggles encountered while trying to set up camera controls in three.js

https://i.sstatic.net/vQdxh.png I've been working on implementing camera navigation functionality in threejs using THREE.OrbitControls. Despite following a tutorial, I'm struggling to get it to function correctly. You can find my code on jsfiddl ...

best practices for passing variables between multiple files within a nodejs application

// script.js var mydata = 1 module.exports = {mydata}; // file in my codebase var newData = require("../script.js") console.log(newData.mydata); // why is it undefined? I want to declare a variable as global across the entire project. I tried using ...

Nextjs: If you encounter a file type that requires special handling, make sure you have the necessary loader configured to process it. Otherwise, the file will

I encountered the following error while attempting to run my Next.js application: ./node_modules/canvas/build/Release/canvas.node Module parse failed: Unexpected character '' (1:2) You may need an appropriate loader to handle this file type, curr ...