Note that there are some explanatory texts on larger screens.

plurals
  1. POClient side validations in Rails with forms in a jQuery slider
    text
    copied!<p>I have a site, which has a jQuery based slider <a href="http://www.awkwardgroup.com/sandbox/awkward-showcase-a-jquery-plugin/%20%22Awkward%20Showcase" rel="nofollow">Awkward Showcase</a>.</p> <p>In these slides I have a Rails form for new user registration. I'm using the <a href="https://github.com/bcardarella/client_side_validations" rel="nofollow" title="Client side validations">client side validation gem</a> for, well, client side validation.</p> <p>The trouble is that because the form is on the second .showcase-slide, it does not exist in DOM when the page loads, and client side validation doesn't work.</p> <p>I need a way to use the hook found at client side validation's GitHub page, to activate client side validations when my element is loaded.</p> <p>So how do I use the hook <code>$('form#user_new[data-validate]').validate();</code> on my form, which has an id of <code>user_new</code>, and isn't loaded immediately and disappears from DOM when you change the showcase slide.</p> <p>I tried several <code>.live</code> and <code>.bind</code> variations, but obviously my jQuery is very weak and I had no luck.</p> <p>Help, please? </p> <h1>Update</h1> <p>I have tried this:</p> <pre><code>$("body").delegate("#user_username", 'focus', function(){ $('form#user_new[data-validate]').validate()}); </code></pre> <p>But now every time I click on the #user_username field, another validation gets added to the stack and I get multiple errors (clones) displayed for a single field.</p> <h1>Another update and an ugly solution</h1> <p>Ok, this is what I've come up with, but it sure is ugly. Any nicer solution is welcome!</p> <pre><code>$("body").delegate("#user_username", 'focus', function(){ if ($('form#user_new[data-validate]').data('events') === undefined ) { $('form#user_new[data-validate]').validate() }}); </code></pre>
 

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