Choosing a value in VueORSelecting

Having some issues with vue select. I have a function that should return the id as the value and display the text as an option, but it is currently returning the full object of the selected value. For instance:

I am fetching selectable options from my backend which look like this:

    {
                "id": 179,
                "name": "Poland",
                "text": "Poland",
                "value": "Poland"
            },
            {
                "id": 100,
                "name": "Hungary",
                "text": "Hungary",
                "value": "Hungary"
            },
        {
            "value": "select_value"
        }

My vue select element is structured like this:

<v-select id="country" v-model="product_info.country" :options="activeCountries" :selectable="option => ! option.value.includes('select_value')" label="text" />

And Vue is returning the entire object of the selected value, such as:

"country":{
            "id":100,
            "name":"Hungary",
            "text":"Hungary",
            "value":"Hungary"
         },

How can I specify in the select form to only return the id, for example:

"country":100

I understand there might be an issue with my v-select setup, but if you believe the problem lies elsewhere in the code, please let me know so I can provide additional information.

Answer №1

To implement the functionality, utilize the item-value prop in this manner:

<v-select item-value="id" id="country" v-model="product_info.country" :options="activeCountries" :selectable="option => ! option.value.includes('select_value')" label="text" />

For further details, refer to the vuetify documentation(https://vuetifyjs.com/en/api/v-select/#props)

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

When should ng-repeat be utilized: only when the object type is an array?

I have a detailed object structure below: $scope.document = { "GENERAL_FIELDS": { "Source_Type": "custom", "Annotations": [ "216/content/Factiva_CM_001/Proteins", "216/content/Factiva_CM_001/Fact" ], "Content": [ " ...

Set up global variables for components to access

Currently, I am working on a Laravel 8 project with vue-sweetalert2 integration. My goal is to set up the Toast behavior once and then be able to call it within various components. At the moment, my code looks like this: /js/components/Mypage.vue <scr ...

Encountering an issue during the project build in Vue specifically related to ffmpeg.wasm

Hey there, I'm encountering the following error when trying to build the project using the $npm run build command https://i.stack.imgur.com/he8tb.png Currently, I am utilizing vuetify version "vuetify": "^2.4.0" since version 3.0 is still in beta. A ...

Is there a Google Maps feature that displays clusters in a dropdown

Currently, I am utilizing Google Maps to place pins all over the world and implementing markercluster.js to cluster those pins when they are nearby. One feature I am trying to incorporate is the ability to hover over a cluster of pins and have a dropdown d ...

An error popped up as I attempted to load an existing design within the vue-email-editor

https://i.stack.imgur.com/0ObU5.png Check out the code snippet below for the function I have created: editorLoaded() { this.$refs.emailEditor.editor.loadDesign(this.emailJson); console.log('editorLoaded'); }, ...

Click to toggle information using Jquery

I am attempting to create a button that, when clicked, will toggle between displaying temperature in Fahrenheit and Celsius. While I have been able to make it work initially, the toggle only occurs once and then stops. I have experimented with separate if ...

Unable to properly bind events onto a jQuery object

I have been attempting to attach events to jquery objects (see code snippet below), but I am facing challenges as it is not functioning properly. Can someone provide me with a suggestion or solution? Thank you! var img = thumbnail[0].appendChild(document. ...

Using arrays to create visual Google charts

I am attempting to pass an array of numbers to a Google chart by extracting the array from a div with the class .likescount. var i, $mvar = $('.likescount'); function logit( string ) { var text = document.createTextNode( string ); $(&a ...

Replicate styling while copying CodeMirror code

Is there a way to maintain the styling and formatting of javascript code when copying from CodeMirror? Whenever I try to copy and paste from the CodeMirror editor, the coloring and style are lost, with the content pasted as text/plain. How can I preserve ...

Infinite loop triggered by jQuery dropdown menu on page resize was causing an issue

I have been working on developing a navigation menu for a website that displays as a horizontal bar on larger screens, but transforms into a jQuery dropdown menu when the window width is less than 980px. During initial page load with a window width below ...

Maximizing CSS opacity for optimal performance in image fading

I'm working on creating a smooth fade in-out effect for the images in my photo gallery by adjusting the CSS opacity value using JavaScript. However, I've noticed that this process is quite sluggish on certain computers, such as my relatively new ...

Is there a way I can obtain the code for a message box?

When I refer to a message box, I am talking about a container that gives users the ability to input their text and access different features like BOLD, ITALIC, color, justify, etc., in order to customize their message's appearance! (Think of it as the ...

"Troubleshooting: Vue JS Axios Post Request Not Passing Data to PHP Server

After successfully uploading an image in Vue JS and sending a POST request to a Laravel Route, the JSON response from the API is displayed on the client side as expected. However, there seems to be an issue with retrieving this response in PHP, as it retur ...

Issue with adding json_encode to the end

I am trying to add the service using jQuery.each(), but it is not working in my JavaScript code? This is the output I am getting from my PHP code: { "data": [{ "service": ["shalo", "jikh", "gjhd", "saed", "saff", "fcds"], "address": " ...

Convert the list items into JSON format

<div class="col-xs-4 no-padding contenteditable-color" style="background-color: transparent;"> <ul class="ul-product"> <li class="li-product-page cars contenteditable" contenteditable="false">qweryt</li> </ul&g ...

AngularJS 500 server error

In my current project, I am developing a straightforward angularjs - J2EE application that fetches data from a mysql server and then displays it on an HTML page. The angular function is triggered on form submission as shown below: <div id="register_for ...

Adding query parameters dynamically in Vue without refreshing the component

I'm attempting to update the Query Parameters in Vue without refreshing the component using Vue-Router. However, when I use the code below, it forces a component reload: this.$router.replace({query: this.filters}); Is there a way to prevent the comp ...

Show information upon opening

I am currently working on a project that involves 4 different divs, and I need the content of each div to be displayed based on dropdown selection. I found a code snippet that was close to what I needed, but after trying to adjust it, I haven't been a ...

Table header containing the weekdays for a jQuery calendar display

I need some assistance in creating a basic monthly calendar using a table. Check out this demo: www.jsfiddle.net/pzdw0s2n/1/ ...

How to work with multiple selections in React material-ui Autocomplete

I'm currently using Material-ui Autocomplete in multiple selection mode. My goal is to retrieve all the selected values when the form is submitted. Although I found a solution on how to get individual values through the onChange event handler from thi ...