Kartik Growl And Ajax Response

Hello

@kartik I am trying to use http://demos.krajee.com/widget-details/growl

I have an ajax button that returns a success, and controller sets a setflash msg

Upon this successful ajax request I want to show that flash msg through the growl notification widget.

Is this possible?

The only way i could get growl to work is w/o the widget and simply calling the following on success

$.growl.notice({ title: "Growl", message: "The kitten is awake!" });

http://ksylvest.github.io/jquery-growl/

Should i stick with working option or can the kartik widget display after ajax response?

Thanks

Dennis

Dennis, after an ajax response to show/hide you must typically use javascript to control display of the messages. The widget asset may help you in just loading the assets on the page for you to be able to do that.

The widget is normally useful for the standard controller redirect or render actions where you may want to display a flash message (without necessarily using ajax).

Gotcha. I was just trying to see if there was a way to "Execute" the widget in javascript upon success.

I have a solution…

Put the widget in the view but comment out position…




        'position' => [

            // 'from' => 'top',

            // 'align' => 'right',

        ]



Therefore does not show anything but does register components (css/js)

in controller put the following…




        $growl = [ 

            'title' => "Group members updated.<hr>",

            'icon' => 'glyphicon glyphicon-ok-sign',

            'message' => "{$inviteCnt} user(s) invited.",  

            'showSeparator' => true,

        ];


        echo Json::encode(['response'=>'success', 'growl' => $growl ]);



and on ajax success…




$.growl( data.growl );



A little round about but working.

I think it could be better if you render Kartik Grow just when you need it.

This way you don´t worry about assets, and have a reusable code.

My sugestion is:

make a view with just the widget, and call it _success.php.

in your controller, make an actionSuccess, where you renderAjax _success.php.

In the view you want to display the grow, make a div just for it.

And in your ajax success, you call this new action:




$('#divForGrow').load('yourController/success');



I have a messagesController, where I build all the messages I need, and use it everywhere.

Best Regards

Thanks for this architecture suggestion.

I have followed this and although it makes an extra call it works very good. I have also integrated the responses into a db table allowing incredible ease of modifying alert messages.

Regards,

Dennis

Hi All,

I do apologise to response in the old thread, but this is what I am looking for. But, I have some questions about it.

  1. Does Growl shown on new layer above the current layer? Is that possible to have it on a div?

  2. If we use pjax, does anyone can give an example of it? I am really lost here…

  3. If we load it using different controller, (say special MessageController or the same kind), is that possible if I want to have this kind of behavior, If return status success, show the growl and hide the form, but if return status is error, show the growl and keep the form including show the error message.