Having difficulty with sending just the selected value using TypeScript

I've encountered an issue with sending the value of a select input to my database while working with Vue, Quasar, and TypeScript.

Within a modal, I have name and age inputs along with a select that chooses a category. However, when attempting to send this select value to the database, an object is sent containing both the label and value of the select. The database requires only a numeric value for it to be accepted.

const baseFieldStates = {
  name: '',
  age: '',
  category:  null,
};
//@ts-ignore
const fieldStates: Ref<UserFormData> = ref({
  ...baseFieldStates,
  ...props.userData
});

Below is the function I am using to save user data in the database.

const userAction = props.userData ? editUser : createUser
const saveUser = () => {
  userAction(fieldStates.value)
    .then(() => {
      onDialogOK(fieldStates.value);
    })
    .catch(() => {
      onDialogCancel();
    })
};

This is how the select input is defined:

          <q-select
            outlined
            class="q-mb-lg"
            :options="rolesOptions"
            option-value="value"
            option-label="label"                
            :label="$t('Users.form.role')"
            v-model="fieldStates.category"
          />

An example of how the select input is currently being sent to the database is shown below.

{label: 'Example', value: 1}

Answer №1

To make sure everything works correctly, don't forget to include both emit-value and map-options. For more information, check out: .

In the Quasar framework q-select, the v-model is set to an object instead of the id

<q-select
outlined
class="q-mb-lg"
:options="rolesOptions"
emit-value
map-options
:label="$t('Users.form.role')"
v-model="fieldStates.category"
/>

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 reason for a class's attributes being considered undefined even after they have been previously set?

Within my code, there is a class called WorkspaceDatabase that stems from the Dynamic Tree Example. I have incorporated some debugging information to gain a clearer understanding of the issue at hand. The Issue: Upon entering the complete() function, an ...

Angular request accessing CoinMarketCap API

Currently, I am immersing myself in the world of the latest CoinMarketCap API and navigating through the waters of data. The Node.js example below demonstrates how to make a request. But how can I achieve the same in Angular? Any tips or suggestions would ...

Vetur's "go to definition" feature is unable to redirect users after pressing alt and clicking

I consider myself a proficient user of Vue and I require the ability to ALT+click (multiCursorModifier) on different Vue components in my project to navigate to their definition/implementation. I have already installed Vetur and configured the following se ...

When clicking on HTML input fields, they do not receive focus

I am facing a puzzling issue where I am unable to access the input fields and textareas on my HTML form. The JS, HTML, and CSS files are too large for me to share here. Could someone provide guidance on what steps to take when troubleshooting this unusual ...

Tips for recognizing users in socket.io?

I'm currently developing a chat application with socket.io. However, one issue I am facing is identifying the sender of a message. Unlike in Express where we have the "req" (request) variable to easily identify users, socket.io does not provide such f ...

Executing TypeScript functions in a sequential order within an Angular2 environment

Here is a Typescript function I have written: AdjustSpinAndGetAmbiguityAnalysisResult() { this.cssRefreshSpin = "glyphicon glyphicon-refresh glyphicon-spin"; this.GetAmbiguityAnalysisResult(); this.cssRefreshSpin = "glyphicon glyph ...

What is causing the list-sorter to malfunction?

This website crashes when executed: <head> <script> var numbersList = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]; var orderedList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, ...

running into an issue while attempting to utilize socket.io

Currently, I am utilising the socket.io swift client on my Iphone SE. Below is the swift code snippet: let socket = SocketIOClient(socketURL: URL(string: "http://example.com:4000")!, config: [.log(true), .forcePolling(true)]); socket.connect(); ...

Dimension of the element that has been positioned absolutely

One of my challenges involves working with an absolutely positioned div element (.tooltip) containing another div (.text) that has text with a set max-width. The issue arises when the left property of .tooltip is too large, causing its width to shrink du ...

I possess a collection of objects, where each object is composed of maximum and minimum key-value pairs. What is the method to determine which object includes a specified value within it?

I have a list of insurance rates structured like this const insuranceRate = [ { "min_value": 1, "max_value": 25000, "add": 328 }, { "min_value": 25001, "max_value": 25500, "add& ...

JavaScript Event Listener causing the Sticky Position to Break

I am currently dealing with a situation where I want to create a slide-in side menu that remains sticky. However, when I apply the position: sticky CSS property to my menu container, it causes the entire menu to be displayed (instead of being pushed off th ...

What could be causing the list items from a JSON file to return as undefined in jQuery?

My dog name tool is functioning properly with a pop-up feature that retrieves names from a separate json file and displays them as list items. Below is the relevant HTML and jQuery code: <div class="dnt-container-mobile seasonal-bg-dark"> <h1 c ...

Is it possible to execute a controller function only when the textarea has completely loaded?

My current setup includes a textarea as shown below: <textarea rows="3" maxlength="144" ng-maxlength="144" type="text" name="testPost" id="testPost_{{item.id}}" ng-init="focusText('testPost', item.id)" ng-model=" ...

How can I resolve the issue with the error "vue/no-multiple-template-root"?

Update: By using v-if and v-else statements, I was able to resolve the issue. However, I would appreciate some guidance on how to prevent this from happening in the future. Issue Summary: The error is caused by having two elements in the template. The Vue ...

Pass information between two forms using the Post method and Ajax communication

For my project, I attempted to retrieve data using the POST method in the processing file but encountered difficulties. I need to be able to receive the data through the POST method and display it on process.php. It's worth noting that my inputs are n ...

Failure of Async Callback in a Loop

Currently, I am developing a Node JS function that involves an array of objects. For each item in the array, I need to make an asynchronous call. for (var i = 0; i < allCases.length; i++) { if (allCases[i].Case_ID != null) { Utils.findAndU ...

Managing Numerous Dropdown Menus: Techniques and Tips

I'm currently working with MUI to design a navigation menu that contains dropdowns within certain links. However, I've encountered an issue where clicking on any button opens the same dropdown menu. Below is my code snippet: function Header() { ...

What is the reason for TS expressing dissatisfaction about the use of a type instead of a type entry being provided

Below is a snippet of code for a Vue3 component that takes in an Array of Objects as a prop: <script lang="ts"> interface CorveesI { What: string, Who: string, Debit: number } export default { name: 'Corvees', props: { ...

Combine the information from another cell and add it to the current cell with additional data

Can you help me figure out a way to input numbers and have Google Sheets calculate the change percentage in the same cell? Here's an example: Oct 20 Nov 20 Dec 20 90 100 (+10%) 95 (-5%) I'm hoping to do this without using additional cell ...

Vue custom directive - encountering undefined object properties

I have a unique Vue directive that I created to display or hide an element based on a specific role. Vue.directive('role', (el, binding, vnode ) => { const modifiers = binding.modifiers const roles = vnode.context.$store.state.roles; if ...