Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I did not found any solution how to use MicrosoftMvcJQueryValidation.js to ajax submit form without modifying it. Here is my workaround :</p> <p>1) add folowing code in "<code>MicrosoftMvcJQueryValidation.js</code>" file, just before "<code>theForm.validate(options);</code>" in <code>"function __MVC_EnableClientValidation(validationContext)</code>" :</p> <pre><code>if (typeof (validationContext.validationOptions) != undefined &amp;&amp; validationContext.validationOptions != null) $().extend(options, validationContext.validationOptions); </code></pre> <p>2) use this js functions to add own options to <code>.validate()</code> method:</p> <pre><code>function setFormValidationOptions(formId, options) { if (typeof (formId) == undefined || formId == null || typeof (options) == undefined || options == null) return; if (window.mvcClientValidationMetadata) { for (i = 0; i &lt; window.mvcClientValidationMetadata.length; i++) if(window.mvcClientValidationMetadata[i].FormId == formId) window.mvcClientValidationMetadata[i].validationOptions = options; } } </code></pre> <p>3) to ajax submit form use :</p> <pre><code>valOpt = { submitHandler: function(form) { $(form).ajaxSubmit({ target: "#output" }); } }; setFormValidationOptions("myFormId", valOpt); </code></pre> <p>Remember you can add any valid <a href="http://docs.jquery.com/Plugins/Validation/validate#toptions" rel="nofollow noreferrer">options</a> for .validate() function. Both jquery.validate and jquery.forms plugins must be loaded.</p> <p>Hope it helps.</p>
 

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