Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am adding the answer. Sorry for the delay guys.</p> <p>First credit to the plugin:<a href="https://github.com/posabsolute/jQuery-Validation-Engine">https://github.com/posabsolute/jQuery-Validation-Engine</a> . Used the plugin for validations in the application.</p> <p>In the view, i had</p> <pre><code>&lt;%= f.username_field :username, :id =&gt; 'free-user', :placeholder=&gt;'User Name', :class =&gt; "validate[required, ajax[ajaxUserCall]]", "data-prompt-position" =&gt; "topLeft:0,9"%&gt; </code></pre> <p>In the same view, in java script: </p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function(){ $("#free-user").bind("jqv.field.result", function(event, field, errorFound, prompText){ if(errorFound){ $(".continue").attr("disabled", false); // .continue is a button } else{ $(".continue").attr("disabled", true); } }) }); &lt;/script&gt; </code></pre> <p>In routes.rb i have the following route.</p> <pre><code>match '/check-user' =&gt;"users#check_user" // creating route for ajax call </code></pre> <p>In jquery.validationEngine-en.js file i have following:</p> <pre><code>"ajaxUserCall": { "url": "/check-user", // you may want to pass extra data on the ajax call "alertText": "* This user is already taken", "alertTextLoad": "* Validating, please wait" }, </code></pre> <p>In users controller, i have the following method</p> <pre><code>def check_user user = params[:fieldValue] user = User.where("username = ?", username).first if user.present? render :json =&gt; ["free-user", false , "This User is already taken"] else render :json =&gt; ["free-user", true , ""] end end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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