Meteor SimpleSchema: prevent form submission using asynchronous custom validation -


i have implemented custom validation function using example referenced in simpleschema documentation validating uniqueness of username. in example, asynchronous call made , custom validation message displayed if username found exist.

there note, indicates if of form fields valid, form submitted, user creation fail due "unique: true" requirement specified in schema. here relevant portion of code example docs:

username: {  type: string,  regex: /^[a-z0-9a-z_]{3,15}$/,  unique: true,  custom: function () {    if (meteor.isclient && this.isset) {      meteor.call("accountsisusernameavailable", this.value, function (error, result) {     if (!result) {           meteor.users.simpleschema().namedcontext("createuserform").addinvalidkeys([{name: "username", type: "notunique"}]);           }     });    }   } } 

in case, have code working testing if activation code valid, interface display error, since there no other "schema" failure, form submits, despite invalid response... need manually prevent form submission (i.e. using jquery), or there in simpleschema should use instead?

activationcode: {     type: string,     label: "activation code",     max: 200,     min: 10,     regex: /^(?=.*[a-z])(?=.*\d).+$/,     custom: function() {         if (meteor.isclient && this.isset) {             meteor.call("validateactivationcode", this.value, function(error, result) {                  if (result && !result.isvalid) {                     clients.simpleschema().namedcontext("signupform").addinvalidkeys([{                         name: "activationcode",                         type: "notvalid"                     }]);                      return false;                 }             });         }     } } 

thank you


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -