Getting the ID of a select input option in Vue.js using FormulateInput

Recently, I've been working with a FormulateInput select component that looks like this:

<FormulateInput
   name="broj_zns-a"
   @change="setZns"
   :value="brojZnsa"
   type="select"
   label="Broj ZNS-a*"
   validation="required"
   :validation-messages="{required: 'Ovo polje je obavezno'}"
   :options="this.brojeviZnsa"
   :placeholder="this.brojeviZnsa.length > 0 ? 'Odaberite' : 'Nema podataka'"
/>

The options for this component are obtained from an API and structured as follows:

let brojeviZnsa = res.data.map(zns => ({
    'value': zns["zns_unos_podataka_broj_znsa"],
    'label': zns["zns_unos_podataka_broj_znsa"],
    'id': zns["id"],
}));
this.brojeviZnsa = brojeviZnsa;

One issue I have encountered is the inability to fetch the "id" of the selected option in the change event handler:

setZns(e) {
    this.getZns(e.target.value);
},

While e.target.value provides the value of the current selection, I actually require the "id" for the getZns function.

I did attempt using e.target.id, but unfortunately, it returns undefined.

I appreciate any assistance you can offer on this matter!

Answer №1

Remember to use the value attribute for the Id

If you need a reference, you can check out the Vue Formulate documentation here: Inputs / Select

Vue.use(VueFormulate)
const app = new Vue({
    el: '#app',
    data(){      
      return { value: null }
    }
})
#app { line-height: 1.75; }
[v-cloak] { display: none; }
<link href="
https://cdn.jsdelivr.net/npm/@braid/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="592f2c3c74414a5c517b454042450653535d7c745241455c5114475955566559535d">[email protected]</a>/dist/snow.min.css
" rel="stylesheet">
<div id="app" v-cloak>
value: {{value}}<br/>
<formulate-input
  v-model="value"
  type="select"
  :options="[
    { value: 'first', label: 'First name' },
    { value: 'last', label: 'Last name' },
    { value: 'initial', label: 'Middle Initial', id: 'name-initial' },
    { value: 'maiden', label: 'Maiden name', disabled: true },
  ]"
></formulate-input>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script>
<script src="https://unpkg.com/@braid/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="593e3d2d651e172a252d34392c3d184a565d565b4e6a28243824393819294840">      </a>/dist/formulate.min.js"></script>

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

I am in the process of transforming my basic JS Array into one that contains key/value

Currently, I am utilizing jQuery to create an Array in the following manner: var arr = new Array(); $('#some-form .some-input').each(function() { arr.push($(this).val()); ...

How can the onclick attribute be modified in an HTML document?

I am looking to update the data-pro-bar-percent attribute of a progress bar from 80 to 100 when a specific link is clicked. The change in attribute needs to be as follows: data-pro-bar-percent="80" --> data-pro-bar-percent="100" This is the current HT ...

"Troubleshooting 3D Models not appearing correctly in Mapbox when using Three.js

My issue lies in the inability to load any .gltf file, only a standard one. For further details, please continue reading. The map on my application showcases a 3D model indicated by the red arrow: https://i.sstatic.net/3Ce09.png The model is a GLTF file ...

A guide on invoking a servlet using a jQuery $.ajax() call

I am having trouble calling a servlet using jQuery's .ajax() function. It seems like the servlet is not being called or parameters are not being passed to it. Despite searching extensively online, I have not been able to find a solution. Any suggesti ...

What is the best way to showcase information retrieved using the getDocs function from Firebase Firestore?

Hello! I am currently exploring the world of Firestore and facing a challenge. My goal is to retrieve a data object from Firestore, set it as state, and then display it on my application: Below are the imports that I have utilized for this task (please ig ...

Tips for managing onClick code when a user selects "open link in new tab" within a React js environment

How can I ensure that my tracking code runs when a user clicks a button in my React project, even if they open it in a new tab? Is there a solution for this in React JS? Here's a simple example: var Hello = React.createClass({ render: function( ...

The `sameAs` validator in vuelidate does not function properly when using the `not` validator with a computed value

I am facing an issue with getting the not validator to work in conjunction with a computed sameAs value. While I am using the term "computed" here, I am not completely certain if it is the most accurate term. Hopefully, alongside the reproducible code pr ...

Assign a variable to the result of ajax that remains unchanged until it is specifically invoked

I am currently working on the final part of my radio script, specifically focusing on the "last song" section. My goal is to retrieve a URL from an external PHP script, play the song, and once the song ends, I want to set a global variable equal to the cur ...

jQuery fails to operate on products loaded through AJAX requests

Upon opening the page, jQuery functions correctly. However, when a product is loaded or changed via AJAX, jQuery stops working. I am currently using jquery-1.7.1.min.js $(document).ready(function () { $screensize = $(window).width(); if ($screensi ...

capturing the value of a button during the onChange event

I'm currently trying to retrieve the button value within an onChange event. My goal is to then bind this value to state, but unfortunately, I am receiving an empty value. <button onChange={this.handleCategoryName} onClick={this.goToNextPage}> ...

Issue with button events not being triggered while working with dynamically created classes

I am facing an issue with three plus (+) buttons that are next to three separate tables built using DataTables. The problem arises because all the plus buttons were created in one location with DataTables, resulting in them being assigned the same classes ...

A variant of setTimeout designed specifically for family members

I am currently working on a program that involves creating a "health" variable which decreases by random amounts at random intervals. This means that a player may encounter scenarios like the following: 5 seconds Lose 20 health 3 more seconds Lose 25 healt ...

Performing an HTTP GET Request in Node.js or Express.js

Currently, I am working with express.js and require assistance in making an HTTP GET request to retrieve JSON data. Can anyone recommend some reliable node js/express js modules or libraries that can help me with performing get/post requests? ...

Assigning an identification number to specify the type of Chip

I am currently working on a project involving Material UI "Chips" that contain text and serve as references. Within the context of my project, I have Chips for both White Advantages and Black Advantages sections. However, there are instances where these Ch ...

Sending HTML input data to jQuery form field

Is there a way to pass HTML text input values into a Stripe form? Here is an example of what I currently have: <input type="text" name="trip" id="trip" value=""> JS: (part of the form) .append(jQuery('<input>', { 'nam ...

In the world of Node.js, an error arises when attempting to read properties of undefined, particularly when trying to access the

I am currently attempting to integrate roomSchema into a userSchema within my code. Here is the snippet of code I am working with: router.post('/join-room', async (req, res) => { const { roomId, userId } = req.body; try { const user = ...

Value in any array matches

I need help finding a match array within an input value: var values = new Array('stackoverflow', 'google', 'yahoo'); var userInput = $('#txtAddress').val(); if ($.inArray(userInput, values) != -1) { alert(&apos ...

What is the best way to invoke a function using a string as its name?

In my grid configuration function, I am assigning column definitions. One key, valueGetter, requires a function to be called to fetch the column value. The issue I am encountering is that the API returns this value as a string. When I try to set it using ...

Error encountered while using Jquery's .each() method on a DOM element and attempting to

Trying to utilize the each() function on my DOM to dynamically retrieve a field, I encountered an issue with the following code: var new_entry = new Object(); $('div[name="declaration-line-entry"]').each(function () { new_entry.name = $(this ...

Do the dependencies in the devDependencies section impact the overall size of the

My search for a definitive answer to this question was fruitless. Are the packages I include as devDependencies included in the final production JS bundle, impacting its size? Or does only the dependencies list affect the bundle's content? ...