Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The example on Modalbox has the validation error already hidden in the lightbox: &lt;p style="display:none">Invalid Email!&lt;/p> so I think if you want to use Grails validation, you will have to take control over the form yourself. In this case the lightbox plugin will only be responsible for drawing the lightbox, and you will provide all the form contents.</p> <p>I use Boxy (another lightbox plugin which should work similarly to your Modalbox) and here's an example of how I use Grails validation within the lightbox. When I create the lightbox I use a "shell" action to fill it. The shell action renders a template, and inside the template is a &lt;g:include&gt; which draws the search form the first time. &lt;g:formRemote&gt; calls a validation action and redraws the contents of the lightbox with the results of the validation action. The results could be either be a success page or a validation error page.</p> <p>The use of a command object, in this example SearchCommand, is just for demonstration. </p> <h2>Controller:</h2> <pre><code>def launchLightbox = { render template: 'lightboxFrame' } def lightboxContents = { SearchCommand cmd -&gt; // if the search failed, re-draw the search form with validation errors if (cmd.hasErrors()) { return [cmd: cmd] } // the search succeeded. Show the results within the lightbox else { render template: 'searchResults', model: [results: cmd.results] } } </code></pre> <h2>_lightboxFrame.gsp:</h2> <pre><code>&lt;g:formRemote name="searchLightbox" url="[action: 'lightboxContents']" update="lightboxContentsDiv"&gt; &lt;div id="lightboxContentsDiv"&gt; &lt;g:include view="/yourController/_lightboxContents.gsp"/&gt; &lt;/div&gt; &lt;/g:formRemote&gt; </code></pre> <h2>_lightboxContents.gsp:</h2> <pre><code>&lt;g:renderErrors bean="${cmd}"/&gt; &lt;p&gt;Enter your search:&lt;/p&gt; &lt;g:textField name="search" value="${cmd?.search}"/&gt; &lt;g:submitButton name="submitButton" value="Submit"/&gt; </code></pre> <p>If you want more control over what to do when the search succeeds or fails, for example to either render the validation errors on failure or close the lightbox on success, you'll probably need to write your own javascript callback.</p> <p>Somewhat related to this problem, and it may be helpful to you, is the <a href="http://www.grails.org/plugin/remote-constraints" rel="nofollow noreferrer">Grails Remote Constraints plugin</a>. I haven't tried it in a while, but you should be able to use it to redraw portions of your page asynchronously with validation errors generated by Grails.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload