Search code examples
javascriptjqueryjquery-validation-engine

Is it possible to call $('form').validationEngine('validate') with some custom options?


I want to use the 'validate' method that is included jquery validation engine plugin, whilst also be able to pass in a few available options to ensure that the validation errors show in the correct way, such as the 'promptPosition' option.

Due to the nature of the framework that I am using which is Meteor.js, I cannot use the default submit functionality to submit a form, nor can I use Ajax straight off the bat. I would have to override default submit functionality, validate the form, then do the manipulations that I need to do to the backend, which is in javascript.

Is it possible to do something like this with this plugin?

$('form').validationEngine('validate', {promptPosition: 'topLeft' });

I know that you can just use: $('form').validationEngine('validate') but I do need some the plugin's custom options available similar when you use the 'attach' method.

Cheers.


Solution

  • I isn't possible to define options when calling validate. The only solution I can think of is to use something like this:

    var myForm = $("form");  
    myForm.validationEngine('attach', {promptPosition : "topLeft"});
    // other js... 
    // when you want to validate the form use:
    myForm.validationEngine('validate');
    

    You set the desired options when "attaching" the validation engine. You then trigger the validation manually. To prevent the validation getting triggered by the user just use a button instead of input type="submit".

    Here's a demo of what I'm trying to explain: http://jsfiddle.net/jxWp8/2/