yii2mod / yii2-sweet-alert

SweetAlert widget for Yii2 framework
MIT License
43 stars 18 forks source link

Not initialize when page render #12

Open dzero1 opened 5 years ago

dzero1 commented 5 years ago

I start to use this as a replacement to data-confirm alerts. So I noticed sweetalert-min.js is not loading and always say swal is not defined. So when I go through you doc and found should insert "echo Alert::widget();" but no luck. (But it work after if I create a alert with title)

Then I check you code found it happen with a title checking inside the "registerAssets()" in Alert.php. So I commented if statement. Then it's fine.

here the new code:

protected function registerAssets(){
       //if ($this->hasTitle()) {
            $view = $this->getView();
            AlertAsset::register($view);
            $js = "sweetAlert({$this->getOptions()}, {$this->callback});";
            $view->registerJs($js, $view::POS_END);
        //}
}

Check this and update.

Anyway, Thanks for the plugin.