javascriptgrailsgritter

Grails flash message w/ gritter


Normally the message appears by using

<g:if test='${flash.message}'>
    <div>${flash.message}</div>
</g:if>

whenever an action is triggered.

How do you set it to appear like a gritter notification? So that say i click a submit button

<button class="btn btn-primary" data-dismiss="modal" type="submit">Log me in</button>

A pop-up on the upper right will appear. Here's the gritter snippet. I find it hard since im new to javascript

$('#flash-message').click(function(){

        $.gritter.add({

            title: 'Notice',            
            text: '${flash.message}',           
            image: '',               
            sticky: false,  
            time: ''
        });

        return false;

    }); 

Solution

  • Just wrap the g:if around the JavaScript block, so it won't be generated if there's no message.

    PS: you will probably need to rewrite the content of your gritter text attribute, I'm not sure it's going to work like that.