1

I have this form with two inputs, Options (multiselect) and Amount

I have managed to add Amount to new Form but I failed to add the selected option.

HTML

 <template>
    <div class="container">
        <form @submit.prevent="submitForm" @keydown="form.onKeydown($event)">
            <h5 class="form-header">
                Vue JS form - Laravel
            </h5>
            <div class="form-group row">
                <label class="col-form-label col-sm-4" for=""> Options</label>
                <div class="col-sm-8">
                    <multiselect
                        v-model="selected"
                        :options="options">
                    </multiselect>
                </div>
            </div>
            <div class="form-group row">
                <label class="col-form-label col-sm-4" for=""> amount</label>
                <div class="col-sm-8">
                <input v-model="form.amount" type="text" name="amount" class="form-control" >
                </div>
            </div>
            <div class="form-buttons-w text-right">
                <button class="btn btn-primary" type="submit">Save</button>
            </div>
        </form>
    </div>
  </template>

JS

<script>
    export default {
      data(){
        return {
          selected: null,
          options: ['One', 'Two', 'Three'],
          form: new Form({
            amount : ''
          })
        }
      },
      methods : {
        submitForm(){
          this.form.post('api/transaction')
        }
      },
      mounted() {

      }
    }
</script>

How can I get the selected option (multiselect) in submitted data ? The same way am getting entered amount.

3
  • 1
    Why don't you try v-model="form.selected" ? Commented Mar 26, 2019 at 10:16
  • 1
    Add multiselect property to form and use v-model as @TohidDadashnezhad mentioned Commented Mar 26, 2019 at 10:33
  • Thanks Tohid & Emīls for the help .. I just added v-model="form.selected" and added the property to the form .. Any of you can write it as answer .. because I can't set comment as answer and I don't want to take the credit. Commented Mar 26, 2019 at 10:44

1 Answer 1

1

You can do like this

 <div class="form-group row">
     <label class="col-form-label col-sm-4" for=""> Options</label>
         <div class="col-sm-8">
              <multiselect
               v-model="form.selected"
               :options="options">
              </multiselect>
         </div>
 </div>
<script>
export default {
  data(){
    return {
      selected: null,
      options: ['One', 'Two', 'Three'],
      form: new Form({
        amount : '',
        selected:[],
      })
    }
  },
  methods : {
    submitForm(){
      this.form.post('api/transaction')
    }
  },
  mounted() {

  }
}    </script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.