JQuery check extension method not working

I am adding the rule below to the existing jQuery Validate script using extension , but this fragment forces it to interrupt and not check at all. I tried all possible combinations of commas before and after, and I also tried using the accept method with mimetypes, but nothing has worked so far. If I comment on this snippet (and the comment on the line before it), the code works fine, but adding this causes it to break.

Here's jsFiddle with as-is code (doesn't work) and here is one with exactly the same code, except the fragment is commented out (works fine).

The fragment itself:

 form1upload: { extension: "jpg|jpeg|pdf|doc|docx|png" } 

Full code:

 jQuery(document).ready(function() { jQuery("#grantapp").validate({ errorClass:"errorlabels", rules: { form1name: "required", form1building: "required", form1position: "required", form1phonex: "required", form1besttime: "required", form1projtitle: "required", form1benefit: "required", form1timeframe: "required", form1relevance: "required", form1description: "required", form1amount: "required", form1acceptchk: "required", form1upload: { extension: "jpg|jpeg|pdf|doc|docx|png" } }, messages: { form1name: "You must enter your name.", form1building: "You must enter your building.", form1position: "You must enter your position.", form1phonex: "You must enter your phone extension.", form1besttime: "You must enter the best time to contact you.", form1projtitle: "You must give your project a title.", form1benefit: "You must enter the number of students who will benefit.", form1timeframe: "You must enter a time frame for this project.", form1relevance: "<br />You must state how this project is relevant to education.", form1description: "<br />You must provide a description of your project.", form1amount: "You must enter a requested amount.", form1acceptchk: "<span style=\"position:relative;top:-10px;\">You must accept the terms.</span>", form1upload: "You may not upload this type of file." }, errorPlacement: function (error, element) { if (element.attr("name") == "form1acceptchk") { error.insertAfter("#tbl1"); } else { error.insertAfter(element); } } }); }); 
+6
source share
1 answer

This is because the extension rule / method is not included in the jQuery Validate plugin by default.

You must enable the jQuery Validate additional-methods.js file plugin if you want to use the extension rule.

It seems to be working now ...

http://jsfiddle.net/tMRer/

+15
source

All Articles