0

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;

    }); 
Jan
  • 3,393
  • 4
  • 21
  • 47
  • Supposing that your gritter code works (I don't know what it is), you're binding the callback to a click on the html element with id="flash-message", which I can't see on the submit button for instance. Is it what you want to accomplish? In that case, add the id attribute to the button. – lucke84 Jan 09 '14 at 12:11
  • @lucke84 is there a callback to just show it? then i would just put it in a div – Jan Jan 09 '14 at 12:27
  • There's no "callback to show something". A callback is the code executed responding to an event. The event is the click, so you need to decide who is gonna be clicked (in your current code, the html element with id='flash-message') and what's going to happen (the gritter execution). Is it actually what you want to do? – lucke84 Jan 09 '14 at 13:21
  • @lucke84 ok. but if assign it the submit button it will still show a blank gritter popup even if there is no flash message. I dont know how can i use the `g:if` tag in conjuction with the gritter popup – Jan Jan 09 '14 at 14:36
  • 2
    Then 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. – lucke84 Jan 09 '14 at 14:39
  • @lucke84 i did wrap the `g:if` around the script and then added a same script only w/ a .ready callback since when i submit the page the DOM refreshes. It now works thanks – Jan Jan 10 '14 at 08:51
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/44934/discussion-between-lucke84-and-mudum) – lucke84 Jan 10 '14 at 08:54

1 Answers1

1

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.

lucke84
  • 4,516
  • 3
  • 37
  • 58