keygenqt / yii2-autocomplete-ajax

A simple way to search model id of the attributes model.
https://old.keygenqt.com/work/yii2-autocomplete-ajax
Apache License 2.0
9 stars 14 forks source link

Loading widget in yii2 bootstrap modal window: Uncaught TypeError: $(…).autocomplete is not a function #8

Open Bounce182 opened 4 years ago

Bounce182 commented 4 years ago

I'm trying to load autocomplete widget in bootstrap modal window:

Modal::begin(

    [

        'header' => '<h3>User search</h3>',

        'id' => 'modal',

        'size' => 'modal-lg'

    ]

);

echo '<div id="modalContent"></div>';

Modal::end();

Popup loading:

$(document).ready(function () {
    $('#modalButton').click(function () {
        $('#modal').modal('show').find('#modalContent').load($(this).attr('value'));
    });
});

Form:

$form = ActiveForm::begin(

            [

                'id' => 'user-search-form',

                'enableAjaxValidation' => true,

                'validateOnChange' => false,

                'validateOnBlur' => false

            ]

        );

$form->field($model, 'userId')->widget(keygenqt\autocompleteAjax\AutocompleteAjax::class, [

            'url' => ['users/search'],

            'options' => ['placeholder' => 'Enter user title']

        ]);
ActiveForm::end();

It loads the modal window with the autocomplete field inside, but it looks like widget can't reach jquery UI autocomplete function:

Uncaught TypeError: $(...).autocomplete is not a function

Any ideas?

cepoblete commented 2 years ago

the view of the component must be corrected, since the javascript must be executed after the jquery is loaded

imagen imagen