M
M
Maxim Timofeev2015-02-18 14:18:05
JavaScript
Maxim Timofeev, 2015-02-18 14:18:05

How to show label instead of value in Jquery UI Autocomplete?

I pass the id=>value array to the widget.
When the list is open, I see the value options, but when I select one of the elements, I see not the value, but the id.
That is, I enter "mos" and
see the list:
moskovia
moscow
mosfilm I select
"Moscow"
in the input "4" this is the id for "Moscow". when submitting the form, 4 is passed and the user sees on the page in the input "4" , but should see "Moscow".
Wonders.

<?php
        echo AutoComplete::widget([
            'name' => 'Board[idinbd]',
            'options'=>['id'=>'board-idinbd', 'placeholder' => 'Начните вводить модель...', 'class'=>'form-control'],
            'clientOptions' => [
                'minLength' => '3',
                'delay' => '200',
            ],
        ]);
        $this->registerJs("
$('#board-idinbd').autocomplete({
  source: function( request, response ) {
  var brandmodels = request.term;
                    $.ajax({
                          url: 'ajaxbrandmodels',
                          dataType: 'json',
                          'type': 'get',
                          data: {bm:brandmodels},
                          success: function( data ) {
                                        response( data );
                                    }
                        });
                        }
});
");
        ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pashenka, 2015-04-26
@like-a-boss

add

$('#board-idinbd').autocomplete({
....
        select:  function( event, ui ) {
          return false;
        },

.....
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question