1

Please help, sorry but I'm new with Vuejs and have maybe a simple problem:

  1. How to search data and populate single query on other input tags

  2. How to combine Vue with select2 plugin (Vue didn't work after I combine with select2) Need to input form binding to website input field here is my code:

populate.js

new Vue({

  el: '#penerima',

  data: {
    namapenerima : '',
  },

  computed: {
    website() {

      var url = "/campaign/create1/" + this.namapenerima;

      this.$http.get(url, function(response){
        return response.website;
      });

      return this.namapenerima;
      // return response.website
    }
  }

});

Route:

Route::get('/create1/{namapenerima}', function($namapenerima){
        return App\Donee::where('id', $namapenerima)->first();
    });

Blade:

                            <div id="penerima">
                              <li>
                                <label>Nama Penerima * </label>
                                <div class="fields-area">
                                  <div class="field-col col-md-12">
                                    <select id="namapenerima" name="namapenerima" v-model="namapenerima" class="form-control">
                                      @foreach ($donee as $d)
                                        <option value="{{ $d->id }}"> {{ $d->donee_name }} </option>
                                      @endforeach
                                    </select>
                                  </div>
                                </div>
                              </li>
                              <li>
                                <label>Website</label>
                                <div class="fields-area">
                                  <div class="field-col col-md-12">
                                    <input type="text" v-model="website">
                                    <span class="char-remain">  </span>
                                  </div>
                                </div>
                              </li>
                            </div>

Select2 script:

$('#namapenerima').select2({
    allowClear: "true",
    placeholder: 'Pilih nama penerima donasi'}).on('select2-opening', function()
    {
        $(this).closest('li');
    });

It return id number in website input field, I know there is something missing but dont know what it is

Thank you in advance.

2 Answers 2

2

You need create a directive to control another libraries in vuejs.

Here's an example: https://vuejs.org/examples/select2.html

And your select

<select class="form-control" 
    v-model="namapenerima"
>
    <option v-repeat="d in donee" value="@{{ exam.d }}">@{{ d.donee_name }}<option>
</select>
Sign up to request clarification or add additional context in comments.

Comments

0

If you've landed here simply looking to populate the input field with some text that will not be used as an input value, in HTML5 you can use:

placeholder='some text'

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.