L
L
Leopandro2016-02-23 20:36:51
JavaScript
Leopandro, 2016-02-23 20:36:51

How to register all Asset(js files)?

I am receiving a form file with Ajax, and I need to include the files needed for validation. How can i do this. I tried doing $this->registerJs($script) and my script came with ajax! How to include all asset files?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Voronkov, 2016-02-23
@DmitryVoronkov

In assets/AppAsset.php

<?php
namespace app\assets;

use yii\web\AssetBundle;

class AppAsset extends AssetBundle
{
     ...
    public $js = [
    'js/your_file.js'
    ];
    ...
}

K
Kirill Arutyunov, 2016-02-24
@arutyunov

Use the method to display the form renderAjax:

public function actionForm()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;

        // ...

        return [
            'status' => 'success',
            'html' => $this->renderAjax('_form', [
                // ...
            ])
        ];
    }

It will just connect all the necessary scripts for form validation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question