Ragheb AlKilany
Ragheb AlKilany

Reputation: 933

Yii2 Ajax Filter onblur

I'm new to yii2 web development and it's the first time I work with javascript. I've already made search results appear using JPax. I only need to start filtering results (inside Gridview) as soon as user removes cursor from either search field (name/price) of course without pressing the search button. I think it has to do with onblur. The problem is I don't have any idea where should I start. Do I have to write inline js code inside text fields? Or create an asset? What should I do?

enter image description here

Upvotes: 0

Views: 706

Answers (1)

Sageth
Sageth

Reputation: 1112

I think there are two ways.

1-Create a asset

You can create a asset with your own JS and CSS files

Here a great guide to use it

2-Register only one JS

View Class have a really usefull method, registerJsFile() you can use it to load an specific JS to your view.

In controller you can use:

Yii::$app->view->registerJsFile('path/file.js', [
                                    'depends' => [
                                         'yii\web\YiiAsset',
                                         'yii\bootstrap\BootstrapAsset',
                                    ]
                                ]);

Use depends option to load your js AFTER Jquery

Upvotes: 1

Related Questions