Send the chosen item from the <b-form-select> element to the parent component through props

Using Vue.js, I have successfully created a form where all input fields pass their values except for the <b-form-select> element. How can I pass the value of the selected option in <b-form-select> to the parent component?

Child Component:

<label> 
              for="source"
              class="inline-3-columns--camp-wizard"
            > 
              <span class="title__field">Network</span>
              <b-form-select
                id="source"
                v-model="networkAudience.source"
                data-vv-as="source"
                name="source"
                value-field="value"
                text-field="label"
                :options="sources"
              />            
              <span
                class="title__field"
                data-vv-as="source"
              >
                {{ networkAudience.source }}
                <input
                  v-model="networkAudience.source"
                  name="source"
                  type="hidden"
                  data-vv-as="source"
                >
              </span>
            </label>

Script:


     data() 
    {
        return {
            selectedclientId: null,
            networkAudience: {
                source: '',
                name: '',               
            },
            sources: [     
                {value: "Group1", label:"Group1"},
                {value: "Group2", label:"Group2"}],
        };
    },
    methods: {
        async submit() 
        {            
            axios.post(projConfig.apiRoot + `/s/audiences/${this.audienceId}/network-audiences/`, this.networkAudience)
                .then(response => 
                {
                    this.networkAudiences = response.data;
                    console.log(response);
                    this.$emit('on-success');
                })
                .catch(error =>
                {
                    console.error(error);
                });
        },
    
    }

Parent Component:

<transition
  name="fade"
  @after-leave="VueEvent.$emit('close-preview-panel')"
>
  <preview-panel
    v-if="showAddNetwork"
    :content-classes="'panel__content--camp-creation mw-1150'"
    :title="'Add Network Audience'"
    @close-preview="showAddNetwork = false"
  >
    <template #content>
      <AddNetworkAudience
        :audience-id="currentAudId"
        @on-cancel="showAddNetwork = false"
        @on-success="handleAddNetworkAudienceSuccess"
      />
    </template>
  </preview-panel>
</transition>

Despite trying to modify the submit method, the issue persists.

Upon form submission, the following errors occur:

Network error message

Console log entry

Answer №1

I have developed a code snippet that is functioning properly and meeting the expected requirements. Kindly review the code below and inform me of any challenges you may be encountering.

new Vue({
  el: '#app',
  data: {
    networkAudience: {
      source: '',
      name: '',               
    },
    sources: [     
      {
        value: "Group1", label:"Group1"
      }, {
        value: "Group2", label:"Group2"
      }
    ]
  },
  methods: {
    submitForm() {
        console.log(this.networkAudience);
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dbb9b4b4afa8afa9baabf6adaebe9be9f5e9eaf5e9">[email protected]</a>/dist/bootstrap-vue.js"></script>
<link rel="stylesheet" href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="72101d1d0601060013025f04071732405c40443b">[email protected]</a>/dist/bootstrap-vue.css"/>
<div id="app">
  <b-form-select v-model="networkAudience.source"
                 :options="sources"
                 value-field="value"
                 text-field="label"
                 ></b-form-select>
  <div>Selected Option: <strong>{{ networkAudience.source }}</strong></div>
  <button type="submit" @click="submitForm()">Submit</button>
</div>

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

Methods for extracting the date value from a Material UI datepicker?

As a newcomer to React, I am currently working on creating a form that includes a Date picker for scheduling appointments. Since booking appointments in the past is not allowed, I need to disable the days before today in the calendar for the date picker. ...

Differences: Angular ngController vs Controller embedded in Directive

I'm interested in exploring the various scenarios where these two methods of creating a controller can be used: Using ngController: myApp.controller('myController', ['$scope', function ( $scope ) { }]); Creating the controller ...

How can I make the top two divs stay fixed as I scroll down, and then reset back to their initial position when scrolled

Hey there, I'm looking to have a div stay fixed after scrolling within its parent div. <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12"> <div class="fw ofndr-box"> <div class="ofndr-box-half add-here"> <a href="#! ...

What is the best way to trigger the Vue.js ApolloClient middleware to run again?

Within my main.js, I have implemented a code snippet that checks if a certain item exists in the localStorage. If it does, the code will add an Authorization header to the ApolloClient setup using middleware. However, if a new item is added to the localSt ...

Javascript/Webpack/React: encountering issues with refs in a particular library

I've encountered a peculiar issue that I've narrowed down to the simplest possible scenario. To provide concrete evidence, I have put together a reproducible repository which you can access here: https://github.com/bmeg/webpack-react-test Here&a ...

Error in content policy for CSS in Stripe Checkout

I am currently attempting to integrate Stripe Checkout into my Ionic App. I have created a Directive that injects the form into my content view, however, upon execution, the CSS fails due to a content policy violation: checkout.js:2Refused to load the s ...

Exploring the world of typed props in Vue.js 3 using TypeScript

Currently, I am attempting to add type hints to my props within a Vue 3 component using the composition API. This is my approach: <script lang="ts"> import FlashInterface from '@/interfaces/FlashInterface'; import { ref } from &a ...

Ways to retrieve the data from promises after they have been resolved?

I'm struggling to retrieve the values from getPeople(0,4). function getPeople(start, end) { const peopleArray = []; for (let i = start; i <= end; i++) { peopleArray.push( axios.get(`https://www.testsite.net/api/test/workers/ ...

Tips for submitting an Ajax Form with identical Name attributes?

One part of my form consists of input fields with the same 'Name' values that will be stored as an Array. I am attempting to send these values via AJAX to PHP for updating my database. The challenge I'm facing is figuring out how to send t ...

If the user is already authorized in VueJS Router, automatically redirect to the requested URL

Exploring the VueJS router mechanics with this tutorial app from GitHub. When attempting to access a direct link like https://example.com/meetups, the app always redirects to the homepage, even if you are logged in and authorized. How can we allow access t ...

What is the best way to extract JSON data from a remote URL?

Having recently started with JavaScript, I am looking to parse JSON from an external URL using pure JavaScript. Currently, I have the following code: var getJSON = function(url, callback) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, tr ...

Locating a Guild Member using their Alias

I need help locating a GuildMember using their nickname. The nickname is linked to their Roblox name upon joining the server, and I've configured a webhook to transmit a message in a specific channel containing their username and other related details ...

The proper way to define an event delegator's syntax

Typically, when you want to handle a button click event, you would do so like this: $(document).ready(function() { $("button").click(function() { doSomething(); }); }); However, in the scenario of an event delegator, you may need to respon ...

Problems with the functionality of the remote feature in Twitter Bootstrap Modal

Utilizing Twitter Bootstrap, I aim to retrieve HTML from another page and inject it into the modal on my current page. This led me to create a JavaScript function to facilitate this process. Within my 'index.php' file, I include the following: ...

What is the best way to run tests on this asynchronous function using Jasmine?

My role in the service is listo: function () { var promiseResolved = $q.defer(); setTimeout(function () { promiseResolved.resolve(true); }, 2000); return promiseResolved.promise; } During my testing ...

JavaScript code for extracting information from a table

After analyzing the table below: <table id="cart-subtotals" cellspacing="0" class="shop_table shop_table_responsive"> <tbody> <tr class="cart-subtotal"> <th>Subtotal</th> <td data-title="Subtotal"><span ...

Invoking a function sharing the same name as a local variable

The code snippet below is causing me some trouble... var firstPlay = 1; if (firstPlay == 1) { firstPlay(); } If I remove the if statement and simply have: firstPlay(); It works fine, but for some reason it doesn't work with the if statement. ...

Summary in Javascript

After utilizing the inspect code tool in PHPStorm, I received the following message: 'recipient_user.id === app.currentUser.id ? true : false' can be simplified to '!!(recipient_user.id === app.currentUser.id)' I'm wondering: ...

What is the best way to prevent excessive rerenders when verifying if database information has been successfully retrieved?

Hey there, I'm encountering an issue where the if statement check in my code is causing a "too many rerenders" problem. I'm trying to create a delay between pulling data from the database and calculating the BMI. Any suggestions on how to resolve ...

Is there a way to save a base64 image to an excel file?

I need assistance with exporting Excel Charts from NVd3 using Angularjs. Here is the code I have been trying: (jsfiddle) <button id="myButtonControlID">Export Table data into Excel</button> <div id="divTableDataHolder"> <table> ...