Send two field values via axios by utilizing a b-form-select component from the Bootstrap Vue library

I'm struggling to send two fields to my backend, but every time I attempt to do so, both values end up as null in the backend.

I am uncertain about what mistake I might be making.

<template>
  <div id="app">
    <div>
      <b-form-select
        v-model="sport_id_form"
        :options="sport_id_form_options"
        class="mb-3"
        value-field="item"
        text-field="name"
      ></b-form-select>
      <div class="mt-3">
        :Selected
        <strong>{{sport_id_form}}</strong>
      </div>
      <button type="button" class="btn btn-dark" v-on:click="get_sports">Get Sports</button>
    </div>
  </div>
</template>


<script>
export default {
  middleware: ["auth"],
  components: {},
  data() {
    return {
      sport_id_form: [],
      sport_id_form_options: [
        { item: null, name: "Please select an option" },
        { item: { "9": "Tennis" }, name: "Tennis" },
        { item: { "10": "Basketball" }, name: "Basketball" }
      ]
    };
  },
  methods: {
    async get_sports() {
      if (this.errors.any()) {
        return;
      }
      await this.$axios.post(
        "api/sportsid/add_sports/",
        this.sport_id_form + "/" + this.sport_id_form_options
      );
      this.$router.push("/");
    }
  }
};
</script>

When utilizing a form in this manner, everything functions correctly.

<script>
export default {
  middleware: ["auth"],
  data() {
    return {
      form: {
        sport_id: "",
        sport_name: ""
      }
    };
  },
  methods: {
    async submit() {
      if (this.errors.any()) {
        return;
      }
      // check for validity, etc....
      await this.$axios.post("/api/sportsid/add_sports/", this.form);
      this.$router.push("/");
    }
  }
};
</script>

Submitting the form sends the data to the backend and triggers events based on the provided values.

Is there a way to post the data in the same structure as the form while using a dropdown selection?

Answer №1

Modify the format

data() {
    return {
      hobby_id_form: {
        hobby_id: "",
        hobby_name: ""
      },
      hobby_id_form_options: [
        { item: null, name: "Please choose an option" },
        { item: { "9": "Soccer" }, name: "Soccer" },
        { item: { "10": "Baseball" }, name: "Baseball" }
      ]
    };
  },

and pick to

<b-form-select
        v-model="hobby_id_form.hobby_id"
        :options="hobby_id_form_options"
        class="mb-3"
        value-field="item"
        text-field="name"
      ></b-form-select>

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

The server is constantly sending data through Server Sent Events

I am currently a student working on a project involving a social trading platform. I am looking to incorporate a notification system and believe that SSE would be a great fit for this purpose. However, I am facing an issue where my SSE code is sending data ...

Behind the scenes, unable to launch due to Schema Error

My experience with Backstage was going smoothly until I ran into an issue after executing a yarn install this afternoon. Now, whenever I attempt to run yarn dev, it fails with the following error: [0] Loaded config from app-config.yaml [0] <i> [webpa ...

Combining Arrays in AngularJS for ng-repeat Iteration

I store my posts in a .json file, while the likes for each post are saved in a separate php file connected to my database. let likesList = []; $http({ method: 'GET', url: 'data/get_likes.php' }).then(function(response) { ...

Mongoose and ES6 promises are not delivering the expected results

I'm currently working on a piece of code that involves creating an array of promises to save specific numbers. The issue I'm facing is that when the output is printed, it displays the same record 10 times. Below is the code snippet: 'use s ...

Combining Versioning with BundleConfig.cs: A Comprehensive Guide

Encountering a recurring issue where changes made to CSS or Javascript files do not reflect in client browsers unless they manually refresh the page with ctrl+F5. This poses a challenge, especially in a school system with numerous users who may not be awar ...

Obtaining the MasterTableView Edit Form within a Radgrid to acquire a reference to a textbox

Can anyone help me with two things, please? I am struggling to access the currently edited existing row in the Radgrid and also the index of the Edit form when attempting to add a new record to the table. function OnClientSelectedIndexChanged(sen ...

Minimize unnecessary rendering in React when toggling between tabs

I am currently working on a React application that utilizes material-ui to generate tabs. <div className={classes.root}> <AppBar position="static"> <Tabs value={value} onChange={handleChange}> <Tab label="Item One" /> ...

What is the process for including an item in an array within Firestore?

Can someone help me with this code snippet I'm working on: await firebase.firestore().doc(`documents/${documentData.id}`).update({ predictionHistory: firebase.firestore.FieldValue.arrayUnion(...[predictions]) }); The predictions variable is an ar ...

Repetitive NodeJS event triggers within Electron-React application causing unexpected behavior

In my custom software package (referred to as PACKAGE_A), I have implemented various automated tasks using a node script. This package includes a Notifier module that creates and exports an EventEmitter. (The entire project is structured as a Monorepo) co ...

What is the best way to incorporate various styles into one :style attribute?

Within my vuetify project, I encountered a challenge of adding multiple styles to the same style attribute. Specifically, I have successfully implemented a vuetify breakpoint and now wish to include {backgroundColor:'Color'} within the existing a ...

Changing in height by utilizing javascript's style.height animation

When attempting to adjust the height property using JavaScript instead of jQuery, a challenge arises. The issue lies in the inability to reset the height back to zero after setting it to the scrollHeight of the element. The following is the JavaScript cod ...

New navigation menu changes as user scrolls

I'm struggling to find a way to implement a different navigation menu that appears when the user scrolls down. I'm envisioning something similar to this example: My goal is to have #small-menu replace #big-menu once the user starts scrolling. C ...

Regular Expression: do not include comments that are placed inside quotation marks

Using the regular expression /#(.*?)\r?\n|#(.*?)$/g, I was able to parse the following content. However, it also matches the comment within the quotes. How can I prevent this from happening? # # this is a comment # but this is '# not a c ...

Achieve a "upload file" button

I am trying to create an add file button within a sidebar of a standard editor. Here are the steps involved: There is a + button. When clicked, it reveals an input field. The user enters the name of the new file and presses enter on the keyboard to s ...

Look through the contents of each child within a div to locate specific text, then conceal any that do not include it

I want to dynamically hide divs that do not contain the text I specify. Here is the code I have tried: var $searchBox = $('#search-weeazer'); $searchBox.on('input', function() { var scope = this; var $userDivs = $('.infor ...

A collaborative effort on Facebook, Twitter, and GooglePlus involves generating SCRIPT tags collectively

If you're familiar with the javascripts used by platforms like Facebook, Twitter, and Google Plus, you'll recognize them below. Here, I've simply organized them neatly together. How can I utilize jQuery to create the script tags and optimiz ...

What is the best way to make three divs that can be adjusted in size?

Desired Layout: | A | | B | | C | ^ ^ Adjustment Behavior: | A | | B | | C | Current Issue: | A | C | I attempted to enhance the functionality by modifying the provided JavaScript cod ...

Exploring the implementation of Javascript, HTML, PHP, and Ajax in programming

<div class="navigation"> <a class="prev" href="index.php?month=__prev_month__" onclick="$('#calendar').load('index.php?month=__prev_month__&_r=' + Math.random()); return false;"></a> <!-- <div class="title" & ...

Tips for Personalizing Bootstrap 4.3 Through BootstrapCDN

I'm having trouble customizing the Bootstrap 4.3 BootstrapCDN by linking an external CSS file to override it. Even though I have placed the custom CSS file below the Bootstrap one, it doesn't seem to be taking effect. Can anyone explain why? Th ...

Issue with Next.js: Callback function not being executed upon form submission

Within my Next.js module, I have a form that is coded in the following manner: <form onSubmit = {() => { async() => await requestCertificate(id) .then(async resp => await resp.json()) .then(data => console.log(data)) .catch(err => console ...