javascript - Custom validator for backbone.js validation -


I am using Backbone.js to build that check if the email address (entered in a form input ) Has already been taken.

Email is available to the new verifier and you can see below: (Notice: This is CufScript, but below you will get the code changed in standard javascript)

  # == ============================== # Model # ================ ================= Users = Backbone.Model Extension (URL Route: "/ User" Verification: Email: FN: "Email Available" Email Available: (Value, Entry, Computational State) - Ajax Call on Server (Play Framework 2.2.1): " E-mails available "string, if it is not getting an email and returns the email address, then it receives an e-mail = $ check.AJX (jsRoutes.controllers.Signup.isEmailExists (value)) checkEmail. Done (msg) -> Emailfound = msg. If Price Email Huffed Returns "Already Taken "Return) # ================================== # VIEWS # ========= ======================= Signupview = backbone.View Extension (Start: - & gt; Backbone.Validation.bind (this) el: "body" Event: "Change input": "validateInput" validateInput: (event) -> Input = $ (event.currentTarget) inputName = Event.currentTarget.name Input Value = input.val () this.model.set (inputName, inputValue) If this is Model.isValid (inputName) input.removeClass "error" input.addClass "valid" other input .removeClass "valid "Input.Adclass" error "...  

This does not work and why can not I find where I am?

Edit < / Strong>: Changed code in javascript

  var SignUpView, user; Email: {email: {FN: "email available"}}, email is available: function (value, activity, computed state) {var check e-mail; Check Amel = $ .ajx (JsRoutes.controllers.Signup.isEmailExists); e-mail don (function) {var emailfound; emailfound = msg; if (value === emailfound) {return "already taken" SignupView = Backbone.View.extend ({initialize: function () {backbone.Validation.bind (this);}, el: "body", Event: {"Change Input" ":" ValidateInput "}, validateInput: function (event) {Var input, input name, input value; Input = $ (event.currentTarget); Input name = event.currentTarget.name; InputValue = input.val (); This.model.set (inputName, inputValue); If (input.) "Input" (Input "Input"); {input.removeClass ("Error"); Return to Input. Adclose ("Valid");} and {Input .removeClass ("Valid"); Return .AddClass ("error");}}});  

backbone. Validity is sad that the asynchronous verification does not support the verification function. This is basically the limit of basic spine authentication flow

  • Specify async: incorrect option for AJAX calls
  • Apply your own verification flow for this case < / Li>

I personally go with Option 2 because Synchronous AJAX calls will lock the browser until the call is completed.

Update Note:

After answering this question I have done a quick Google search, and it seems that there is an extension for backbone. Validation, asynch validation Please note, I have not used it, nor have it tested in any way :)

link:


Comments