Yii2 ActiveForm textInput onChange

I went through the next person http://www.yiiframework.com/wiki/772/pjax-on-activeform-and-gridview-yii2/ and everything is fine. However, I would like to do a Pjax search through the form data without clicking the submit button. Thus, I am trying to use the onChange event, but cannot find a way to do this. I found a lot of explanation for dropDownList, but there is no information about the textInput onChange event.

+4
source share
1 answer

Here is a solution for creating an instant delayed search:

Javascript Instant Search Feature

Just change your JavaScript-Search-Snippet as follows:

$this->registerJs(
   'function instantSearch() {
        $.pjax.reload({container:"#countries"});  //Reload GridView
    }

    var timer;
    $("document").ready(function(){ 
        //$("#new_country").on("pjax:end", function() {
        $("input").keyUp(function(){
            timer && clearTimeout(timer);
            timer = setTimeout(instantSearch, 200);
        });
    });'
);
0

Source: https://habr.com/ru/post/1614232/


All Articles