Grails flash message w/ gritter

571 views Asked by At

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;

    }); 
1

There are 1 answers

0
lucke84 On BEST ANSWER

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.