jquery.validationEngine.js 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885
  1. /*
  2. * Inline Form Validation Engine 2.5.5.1, jQuery plugin
  3. *
  4. * Copyright(c) 2010, Cedric Dugas
  5. * http://www.position-absolute.com
  6. *
  7. * 2.0 Rewrite by Olivier Refalo
  8. * http://www.crionics.com
  9. *
  10. * Form validation engine allowing custom regex rules to be added.
  11. * Licensed under the MIT License
  12. */
  13. (function($) {
  14. "use strict";
  15. var methods = {
  16. /**
  17. * Kind of the constructor, called before any action
  18. * @param {Map} user options
  19. */
  20. init: function(options) {
  21. var form = this;
  22. if (!form.data('jqv') || form.data('jqv') == null ) {
  23. options = methods._saveOptions(form, options);
  24. // bind all formError elements to close on click
  25. $(".formError").on("click", function() {
  26. $(this).fadeOut(150, function() {
  27. // remove prompt once invisible
  28. $(this).parent('.formErrorOuter').remove();
  29. $(this).remove();
  30. });
  31. });
  32. }
  33. return this;
  34. },
  35. /**
  36. * Attachs jQuery.validationEngine to form.submit and field.blur events
  37. * Takes an optional params: a list of options
  38. * ie. jQuery("#formID1").validationEngine('attach', {promptPosition : "centerRight"});
  39. */
  40. attach: function(userOptions) {
  41. if(!$(this).is("form")) {
  42. alert("Sorry, jqv.attach() only applies to a form");
  43. return this;
  44. }
  45. var form = this;
  46. var options;
  47. if(userOptions)
  48. options = methods._saveOptions(form, userOptions);
  49. else
  50. options = form.data('jqv');
  51. options.validateAttribute = (form.find("[data-validation-engine*=validate]").length) ? "data-validation-engine" : "class";
  52. if (options.binded) {
  53. // bind fields
  54. form.find("["+options.validateAttribute+"*=validate]").not("[type=checkbox]").not("[type=radio]").not(".datepicker").bind(options.validationEventTrigger, methods._onFieldEvent);
  55. form.find("["+options.validateAttribute+"*=validate][type=checkbox],["+options.validateAttribute+"*=validate][type=radio]").bind("click", methods._onFieldEvent);
  56. form.find("["+options.validateAttribute+"*=validate][class*=datepicker]").bind(options.validationEventTrigger,{"delay": 300}, methods._onFieldEvent);
  57. }
  58. if (options.autoPositionUpdate) {
  59. $(window).bind("resize", {
  60. "noAnimation": true,
  61. "formElem": form
  62. }, methods.updatePromptsPosition);
  63. }
  64. // bind form.submit
  65. form.bind("submit", methods._onSubmitEvent);
  66. return this;
  67. },
  68. /**
  69. * Unregisters any bindings that may point to jQuery.validaitonEngine
  70. */
  71. detach: function() {
  72. if(!$(this).is("form")) {
  73. alert("Sorry, jqv.detach() only applies to a form");
  74. return this;
  75. }
  76. var form = this;
  77. var options = form.data('jqv');
  78. // unbind fields
  79. form.find("["+options.validateAttribute+"*=validate]").not("[type=checkbox]").unbind(options.validationEventTrigger, methods._onFieldEvent);
  80. form.find("["+options.validateAttribute+"*=validate][type=checkbox],[class*=validate][type=radio]").unbind("click", methods._onFieldEvent);
  81. // unbind form.submit
  82. form.unbind("submit", methods.onAjaxFormComplete);
  83. // unbind live fields (kill)
  84. form.find("["+options.validateAttribute+"*=validate]").not("[type=checkbox]").die(options.validationEventTrigger, methods._onFieldEvent);
  85. form.find("["+options.validateAttribute+"*=validate][type=checkbox]").die("click", methods._onFieldEvent);
  86. // unbind form.submit
  87. form.die("submit", methods.onAjaxFormComplete);
  88. form.removeData('jqv');
  89. if (options.autoPositionUpdate)
  90. $(window).unbind("resize", methods.updatePromptsPosition);
  91. return this;
  92. },
  93. /**
  94. * Validates either a form or a list of fields, shows prompts accordingly.
  95. * Note: There is no ajax form validation with this method, only field ajax validation are evaluated
  96. *
  97. * @return true if the form validates, false if it fails
  98. */
  99. validate: function() {
  100. if($(this).is("form"))
  101. return methods._validateFields(this);
  102. else {
  103. // field validation
  104. var form = $(this).closest('form');
  105. var options = form.data('jqv');
  106. var r = methods._validateField($(this), options);
  107. if (options.onSuccess && options.InvalidFields.length == 0)
  108. options.onSuccess();
  109. else if (options.onFailure && options.InvalidFields.length > 0)
  110. options.onFailure();
  111. return r;
  112. }
  113. },
  114. /**
  115. * Redraw prompts position, useful when you change the DOM state when validating
  116. */
  117. updatePromptsPosition: function(event) {
  118. if (event && this == window) {
  119. var form = event.data.formElem;
  120. var noAnimation = event.data.noAnimation;
  121. }
  122. else
  123. var form = $(this.closest('form'));
  124. var options = form.data('jqv');
  125. // No option, take default one
  126. form.find('['+options.validateAttribute+'*=validate]').not(":disabled").each(function(){
  127. var field = $(this);
  128. var prompt = methods._getPrompt(field);
  129. var promptText = $(prompt).find(".formErrorContent").html();
  130. if(prompt)
  131. methods._updatePrompt(field, $(prompt), promptText, undefined, false, options, noAnimation);
  132. });
  133. return this;
  134. },
  135. /**
  136. * Displays a prompt on a element.
  137. * Note that the element needs an id!
  138. *
  139. * @param {String} promptText html text to display type
  140. * @param {String} type the type of bubble: 'pass' (green), 'load' (black) anything else (red)
  141. * @param {String} possible values topLeft, topRight, bottomLeft, centerRight, bottomRight
  142. */
  143. showPrompt: function(promptText, type, promptPosition, showArrow) {
  144. var form = this.closest('form');
  145. var options = form.data('jqv');
  146. // No option, take default one
  147. if(!options)
  148. options = methods._saveOptions(this, options);
  149. if(promptPosition)
  150. options.promptPosition=promptPosition;
  151. options.showArrow = showArrow==true;
  152. methods._showPrompt(this, promptText, type, false, options);
  153. return this;
  154. },
  155. /**
  156. * Closes form error prompts, CAN be invidual
  157. */
  158. hide: function() {
  159. var form = $(this).closest('form');
  160. if(form.length == 0)
  161. return this;
  162. var options = form.data('jqv');
  163. var closingtag;
  164. if($(this).is("form")) {
  165. closingtag = "parentForm"+methods._getClassName($(this).attr("id"));
  166. } else {
  167. closingtag = methods._getClassName($(this).attr("id")) +"formError";
  168. }
  169. $('.'+closingtag).fadeTo(options.fadeDuration, 0.3, function() {
  170. $(this).parent('.formErrorOuter').remove();
  171. $(this).remove();
  172. });
  173. return this;
  174. },
  175. /**
  176. * Closes all error prompts on the page
  177. */
  178. hideAll: function() {
  179. var form = this;
  180. var options = form.data('jqv');
  181. var duration = options ? options.fadeDuration:0.3;
  182. $('.formError').fadeTo(duration, 0.3, function() {
  183. $(this).parent('.formErrorOuter').remove();
  184. $(this).remove();
  185. });
  186. return this;
  187. },
  188. /**
  189. * Typically called when user exists a field using tab or a mouse click, triggers a field
  190. * validation
  191. */
  192. _onFieldEvent: function(event) {
  193. var field = $(this);
  194. var form = field.closest('form');
  195. var options = form.data('jqv');
  196. options.eventTrigger = "field";
  197. // validate the current field
  198. window.setTimeout(function() {
  199. methods._validateField(field, options);
  200. if (options.InvalidFields.length == 0 && options.onSuccess) {
  201. options.onSuccess();
  202. } else if (options.InvalidFields.length > 0 && options.onFailure) {
  203. options.onFailure();
  204. }
  205. }, (event.data) ? event.data.delay : 0);
  206. },
  207. /**
  208. * Called when the form is submited, shows prompts accordingly
  209. *
  210. * @param {jqObject}
  211. * form
  212. * @return false if form submission needs to be cancelled
  213. */
  214. _onSubmitEvent: function() {
  215. var form = $(this);
  216. var options = form.data('jqv');
  217. options.eventTrigger = "submit";
  218. // validate each field
  219. // (- skip field ajax validation, not necessary IF we will perform an ajax form validation)
  220. var r=methods._validateFields(form);
  221. if (r && options.ajaxFormValidation) {
  222. methods._validateFormWithAjax(form, options);
  223. // cancel form auto-submission - process with async call onAjaxFormComplete
  224. return false;
  225. }
  226. if(options.onValidationComplete) {
  227. // !! ensures that an undefined return is interpreted as return false but allows a onValidationComplete() to possibly return true and have form continue processing
  228. return !!options.onValidationComplete(form, r);
  229. }
  230. return r;
  231. },
  232. /**
  233. * Return true if the ajax field validations passed so far
  234. * @param {Object} options
  235. * @return true, is all ajax validation passed so far (remember ajax is async)
  236. */
  237. _checkAjaxStatus: function(options) {
  238. var status = true;
  239. $.each(options.ajaxValidCache, function(key, value) {
  240. if (!value) {
  241. status = false;
  242. // break the each
  243. return false;
  244. }
  245. });
  246. return status;
  247. },
  248. /**
  249. * Return true if the ajax field is validated
  250. * @param {String} fieldid
  251. * @param {Object} options
  252. * @return true, if validation passed, false if false or doesn't exist
  253. */
  254. _checkAjaxFieldStatus: function(fieldid, options) {
  255. return options.ajaxValidCache[fieldid] == true;
  256. },
  257. /**
  258. * Validates form fields, shows prompts accordingly
  259. *
  260. * @param {jqObject}
  261. * form
  262. * @param {skipAjaxFieldValidation}
  263. * boolean - when set to true, ajax field validation is skipped, typically used when the submit button is clicked
  264. *
  265. * @return true if form is valid, false if not, undefined if ajax form validation is done
  266. */
  267. _validateFields: function(form) {
  268. var options = form.data('jqv');
  269. // this variable is set to true if an error is found
  270. var errorFound = false;
  271. // Trigger hook, start validation
  272. form.trigger("jqv.form.validating");
  273. // first, evaluate status of non ajax fields
  274. var first_err=null;
  275. form.find('['+options.validateAttribute+'*=validate]').not(":disabled").each( function() {
  276. var field = $(this);
  277. var names = [];
  278. if ($.inArray(field.attr('name'), names) < 0) {
  279. errorFound |= methods._validateField(field, options);
  280. if (errorFound && first_err==null)
  281. if (field.is(":hidden") && options.prettySelect)
  282. first_err = field = form.find("#" + options.usePrefix + field.attr('id') + options.useSuffix);
  283. else
  284. first_err=field;
  285. if (options.doNotShowAllErrosOnSubmit)
  286. return false;
  287. names.push(field.attr('name'));
  288. }
  289. });
  290. // second, check to see if all ajax calls completed ok
  291. // errorFound |= !methods._checkAjaxStatus(options);
  292. // third, check status and scroll the container accordingly
  293. form.trigger("jqv.form.result", [errorFound]);
  294. if (errorFound) {
  295. if (options.scroll) {
  296. var destination=first_err.offset().top;
  297. var fixleft = first_err.offset().left;
  298. //prompt positioning adjustment support. Usage: positionType:Xshift,Yshift (for ex.: bottomLeft:+20 or bottomLeft:-20,+10)
  299. var positionType=options.promptPosition;
  300. if (typeof(positionType)=='string' && positionType.indexOf(":")!=-1)
  301. positionType=positionType.substring(0,positionType.indexOf(":"));
  302. if (positionType!="bottomRight" && positionType!="bottomLeft") {
  303. var prompt_err= methods._getPrompt(first_err);
  304. //destination=prompt_err.offset().top;
  305. }
  306. // get the position of the first error, there should be at least one, no need to check this
  307. //var destination = form.find(".formError:not('.greenPopup'):first").offset().top;
  308. if (options.isOverflown) {
  309. var overflowDIV = $(options.overflownDIV);
  310. if(!overflowDIV.length) return false;
  311. var scrollContainerScroll = overflowDIV.scrollTop();
  312. var scrollContainerPos = -parseInt(overflowDIV.offset().top);
  313. destination += scrollContainerScroll + scrollContainerPos - 5;
  314. var scrollContainer = $(options.overflownDIV + ":not(:animated)");
  315. scrollContainer.animate({ scrollTop: destination }, 1100, function(){
  316. if(options.focusFirstField) first_err.focus();
  317. });
  318. } else {
  319. $("html:not(:animated),body:not(:animated)").animate({
  320. scrollTop: destination,
  321. scrollLeft: fixleft
  322. }, 1100, function(){
  323. if(options.focusFirstField) first_err.focus();
  324. });
  325. }
  326. } else if(options.focusFirstField)
  327. first_err.focus();
  328. if (options.onFailure) {
  329. options.onFailure();
  330. }
  331. return false;
  332. }
  333. return true;
  334. },
  335. /**
  336. * This method is called to perform an ajax form validation.
  337. * During this process all the (field, value) pairs are sent to the server which returns a list of invalid fields or true
  338. *
  339. * @param {jqObject} form
  340. * @param {Map} options
  341. */
  342. _validateFormWithAjax: function(form, options) {
  343. var data = form.serialize();
  344. var type = (options.ajaxmethod) ? options.ajaxmethod : "GET";
  345. var url = (options.ajaxFormValidationURL) ? options.ajaxFormValidationURL : form.attr("action");
  346. var dataType = (options.dataType) ? options.dataType : "json";
  347. $.ajax({
  348. type: type,
  349. url: url,
  350. cache: false,
  351. dataType: dataType,
  352. data: data,
  353. form: form,
  354. methods: methods,
  355. options: options,
  356. beforeSend: function() {
  357. return options.onBeforeAjaxFormValidation(form, options);
  358. },
  359. error: function(data, transport) {
  360. methods._ajaxError(data, transport);
  361. },
  362. success: function(json) {
  363. if (json !== true) {
  364. // getting to this case doesn't necessary means that the form is invalid
  365. // the server may return green or closing prompt actions
  366. // this flag helps figuring it out
  367. var errorInForm=false;
  368. for (var i = 0; i < json.length; i++) {
  369. var value = json[i];
  370. var errorFieldId = value[0];
  371. var errorField = $($("#" + errorFieldId)[0]);
  372. // make sure we found the element
  373. if (errorField.length == 1) {
  374. // promptText or selector
  375. var msg = value[2];
  376. // if the field is valid
  377. if (value[1] == true) {
  378. if (msg == "" || !msg){
  379. // if for some reason, status==true and error="", just close the prompt
  380. methods._closePrompt(errorField);
  381. } else {
  382. // the field is valid, but we are displaying a green prompt
  383. if (options.allrules[msg]) {
  384. var txt = options.allrules[msg].alertTextOk;
  385. if (txt)
  386. msg = txt;
  387. }
  388. methods._showPrompt(errorField, msg, "pass", false, options, true);
  389. }
  390. } else {
  391. // the field is invalid, show the red error prompt
  392. errorInForm|=true;
  393. if (options.allrules[msg]) {
  394. var txt = options.allrules[msg].alertText;
  395. if (txt)
  396. msg = txt;
  397. }
  398. methods._showPrompt(errorField, msg, "", false, options, true);
  399. }
  400. }
  401. }
  402. options.onAjaxFormComplete(!errorInForm, form, json, options);
  403. } else
  404. options.onAjaxFormComplete(true, form, "", options);
  405. }
  406. });
  407. },
  408. /**
  409. * Validates field, shows prompts accordingly
  410. *
  411. * @param {jqObject}
  412. * field
  413. * @param {Array[String]}
  414. * field's validation rules
  415. * @param {Map}
  416. * user options
  417. * @return false if field is valid (It is inversed for *fields*, it return false on validate and true on errors.)
  418. */
  419. _validateField: function(field, options, skipAjaxValidation) {
  420. if (!field.attr("id")) {
  421. field.attr("id", "form-validation-field-" + $.validationEngine.fieldIdCounter);
  422. ++$.validationEngine.fieldIdCounter;
  423. }
  424. if (field.is(":hidden") && !options.prettySelect || field.parent().is(":hidden"))
  425. return false;
  426. var rulesParsing = field.attr(options.validateAttribute);
  427. var getRules = /validate\[(.*)\]/.exec(rulesParsing);
  428. if (!getRules)
  429. return false;
  430. var str = getRules[1];
  431. var rules = str.split(/\[|,|\]/);
  432. // true if we ran the ajax validation, tells the logic to stop messing with prompts
  433. var isAjaxValidator = false;
  434. var fieldName = field.attr("name");
  435. var promptText = "";
  436. var promptType = "";
  437. var required = false;
  438. options.isError = false;
  439. options.showArrow = true;
  440. var form = $(field.closest("form"));
  441. for (var i = 0; i < rules.length; i++) {
  442. // Fix for adding spaces in the rules
  443. rules[i] = rules[i].replace(" ", "");
  444. var errorMsg = undefined;
  445. switch (rules[i]) {
  446. case "required":
  447. required = true;
  448. errorMsg = methods._getErrorMessage(form, field, rules[i], rules, i, options, methods._required);
  449. break;
  450. case "custom":
  451. errorMsg = methods._getErrorMessage(form, field, rules[i], rules, i, options, methods._custom);
  452. break;
  453. case "groupRequired":
  454. // Check is its the first of group, if not, reload validation with first field
  455. // AND continue normal validation on present field
  456. var classGroup = "["+options.validateAttribute+"*=" +rules[i + 1] +"]";
  457. var firstOfGroup = form.find(classGroup).eq(0);
  458. if(firstOfGroup[0] != field[0]){
  459. methods._validateField(firstOfGroup, options, skipAjaxValidation);
  460. options.showArrow = true;
  461. continue;
  462. }
  463. errorMsg = methods._getErrorMessage(form, field, rules[i], rules, i, options, methods._groupRequired);
  464. if(errorMsg) required = true;
  465. options.showArrow = false;
  466. break;
  467. case "ajax":
  468. // AJAX defaults to returning it's loading message
  469. errorMsg = methods._ajax(field, rules, i, options);
  470. if (errorMsg) {
  471. promptType = "load";
  472. }
  473. break;
  474. case "minSize":
  475. errorMsg = methods._getErrorMessage(form, field, rules[i], rules, i, options, methods._minSize);
  476. break;
  477. case "maxSize":
  478. errorMsg = methods._getErrorMessage(form, field, rules[i], rules, i, options, methods._maxSize);
  479. break;
  480. case "min":
  481. errorMsg = methods._getErrorMessage(form, field, rules[i], rules, i, options, methods._min);
  482. break;
  483. case "max":
  484. errorMsg = methods._getErrorMessage(form, field, rules[i], rules, i, options, methods._max);
  485. break;
  486. case "past":
  487. errorMsg = methods._getErrorMessage(form, field,rules[i], rules, i, options, methods._past);
  488. break;
  489. case "future":
  490. errorMsg = methods._getErrorMessage(form, field,rules[i], rules, i, options, methods._future);
  491. break;
  492. case "dateRange":
  493. var classGroup = "["+options.validateAttribute+"*=" + rules[i + 1] + "]";
  494. options.firstOfGroup = form.find(classGroup).eq(0);
  495. options.secondOfGroup = form.find(classGroup).eq(1);
  496. //if one entry out of the pair has value then proceed to run through validation
  497. if (options.firstOfGroup[0].value || options.secondOfGroup[0].value) {
  498. errorMsg = methods._getErrorMessage(form, field,rules[i], rules, i, options, methods._dateRange);
  499. }
  500. if (errorMsg) required = true;
  501. options.showArrow = false;
  502. break;
  503. case "dateTimeRange":
  504. var classGroup = "["+options.validateAttribute+"*=" + rules[i + 1] + "]";
  505. options.firstOfGroup = form.find(classGroup).eq(0);
  506. options.secondOfGroup = form.find(classGroup).eq(1);
  507. //if one entry out of the pair has value then proceed to run through validation
  508. if (options.firstOfGroup[0].value || options.secondOfGroup[0].value) {
  509. errorMsg = methods._getErrorMessage(form, field,rules[i], rules, i, options, methods._dateTimeRange);
  510. }
  511. if (errorMsg) required = true;
  512. options.showArrow = false;
  513. break;
  514. case "maxCheckbox":
  515. field = $(form.find("input[name='" + fieldName + "']"));
  516. errorMsg = methods._getErrorMessage(form, field, rules[i], rules, i, options, methods._maxCheckbox);
  517. break;
  518. case "minCheckbox":
  519. field = $(form.find("input[name='" + fieldName + "']"));
  520. errorMsg = methods._getErrorMessage(form, field, rules[i], rules, i, options, methods._minCheckbox);
  521. break;
  522. case "equals":
  523. errorMsg = methods._getErrorMessage(form, field, rules[i], rules, i, options, methods._equals);
  524. break;
  525. case "funcCall":
  526. errorMsg = methods._getErrorMessage(form, field, rules[i], rules, i, options, methods._funcCall);
  527. break;
  528. case "creditCard":
  529. errorMsg = methods._getErrorMessage(form, field, rules[i], rules, i, options, methods._creditCard);
  530. break;
  531. case "condRequired":
  532. errorMsg = methods._getErrorMessage(form, field, rules[i], rules, i, options, methods._condRequired);
  533. if (errorMsg !== undefined) {
  534. required = true;
  535. }
  536. break;
  537. default:
  538. }
  539. if (errorMsg !== undefined) {
  540. promptText += errorMsg.replace('* ', '') + " ";
  541. options.isError = true;
  542. }
  543. //if option set, stop checking validation rules after one error is found
  544. if(options.showOneMessage === true && options.isError === true)
  545. break;
  546. }
  547. // If the rules required is not added, an empty field is not validated
  548. if(!required && field.val().length < 1) options.isError = false;
  549. // Hack for radio/checkbox group button, the validation go into the
  550. // first radio/checkbox of the group
  551. var fieldType = field.prop("type");
  552. if ((fieldType == "radio" || fieldType == "checkbox") && form.find("input[name='" + fieldName + "']").size() > 1) {
  553. field = $(form.find("input[name='" + fieldName + "'][type!=hidden]:first"));
  554. options.showArrow = false;
  555. }
  556. if(field.is(":hidden") && options.prettySelect) {
  557. field = form.find("#" + options.usePrefix + field.attr('id') + options.useSuffix);
  558. }
  559. if (options.isError){
  560. methods._showPrompt(field, promptText, promptType, false, options);
  561. }else{
  562. if (!isAjaxValidator) methods._closePrompt(field);
  563. }
  564. if (!isAjaxValidator) {
  565. field.trigger("jqv.field.result", [field, options.isError, promptText]);
  566. }
  567. /* Record error */
  568. var errindex = $.inArray(field[0], options.InvalidFields);
  569. if (errindex == -1) {
  570. if (options.isError)
  571. options.InvalidFields.push(field[0]);
  572. } else if (!options.isError) {
  573. options.InvalidFields.splice(errindex, 1);
  574. }
  575. return options.isError;
  576. },
  577. /********************
  578. * _getErrorMessage
  579. *
  580. * @param form
  581. * @param field
  582. * @param rule
  583. * @param rules
  584. * @param i
  585. * @param options
  586. * @param originalValidationMethod
  587. * @return {*}
  588. * @private
  589. */
  590. _getErrorMessage:function (form, field, rule, rules, i, options, originalValidationMethod) {
  591. // If we are using the custon validation type, build the index for the rule.
  592. // Otherwise if we are doing a function call, make the call and return the object
  593. // that is passed back.
  594. var beforeChangeRule = rule;
  595. if (rule == "custom") {
  596. var custom_validation_type_index = jQuery.inArray(rule, rules)+ 1;
  597. var custom_validation_type = rules[custom_validation_type_index];
  598. rule = "custom[" + custom_validation_type + "]";
  599. }
  600. var element_classes = (field.attr("data-validation-engine")) ? field.attr("data-validation-engine") : field.attr("class");
  601. var element_classes_array = element_classes.split(" ");
  602. // Call the original validation method. If we are dealing with dates, also pass the form
  603. var errorMsg;
  604. if (rule == "future" || rule == "past" || rule == "maxCheckbox" || rule == "minCheckbox") {
  605. errorMsg = originalValidationMethod(form, field, rules, i, options);
  606. } else {
  607. errorMsg = originalValidationMethod(field, rules, i, options);
  608. }
  609. // If the original validation method returned an error and we have a custom error message,
  610. // return the custom message instead. Otherwise return the original error message.
  611. if (errorMsg != undefined) {
  612. var custom_message = methods._getCustomErrorMessage($(field), element_classes_array, beforeChangeRule, options);
  613. if (custom_message) return custom_message;
  614. }
  615. return errorMsg;
  616. },
  617. _getCustomErrorMessage:function (field, classes, rule, options) {
  618. var custom_message = false;
  619. var validityProp = methods._validityProp[rule];
  620. if (validityProp != undefined) {
  621. custom_message = field.attr("data-errormessage-"+validityProp);
  622. if (custom_message != undefined)
  623. return custom_message;
  624. }
  625. custom_message = field.attr("data-errormessage");
  626. if (custom_message != undefined)
  627. return custom_message;
  628. var id = '#' + field.attr("id");
  629. // If we have custom messages for the element's id, get the message for the rule from the id.
  630. // Otherwise, if we have custom messages for the element's classes, use the first class message we find instead.
  631. if (typeof options.custom_error_messages[id] != "undefined" &&
  632. typeof options.custom_error_messages[id][rule] != "undefined" ) {
  633. custom_message = options.custom_error_messages[id][rule]['message'];
  634. } else if (classes.length > 0) {
  635. for (var i = 0; i < classes.length && classes.length > 0; i++) {
  636. var element_class = "." + classes[i];
  637. if (typeof options.custom_error_messages[element_class] != "undefined" &&
  638. typeof options.custom_error_messages[element_class][rule] != "undefined") {
  639. custom_message = options.custom_error_messages[element_class][rule]['message'];
  640. break;
  641. }
  642. }
  643. }
  644. if (!custom_message &&
  645. typeof options.custom_error_messages[rule] != "undefined" &&
  646. typeof options.custom_error_messages[rule]['message'] != "undefined"){
  647. custom_message = options.custom_error_messages[rule]['message'];
  648. }
  649. return custom_message;
  650. },
  651. _validityProp: {
  652. "required": "value-missing",
  653. "custom": "custom-error",
  654. "groupRequired": "value-missing",
  655. "ajax": "custom-error",
  656. "minSize": "range-underflow",
  657. "maxSize": "range-overflow",
  658. "min": "range-underflow",
  659. "max": "range-overflow",
  660. "past": "type-mismatch",
  661. "future": "type-mismatch",
  662. "dateRange": "type-mismatch",
  663. "dateTimeRange": "type-mismatch",
  664. "maxCheckbox": "range-overflow",
  665. "minCheckbox": "range-underflow",
  666. "equals": "pattern-mismatch",
  667. "funcCall": "custom-error",
  668. "creditCard": "pattern-mismatch",
  669. "condRequired": "value-missing"
  670. },
  671. /**
  672. * Required validation
  673. *
  674. * @param {jqObject} field
  675. * @param {Array[String]} rules
  676. * @param {int} i rules index
  677. * @param {Map}
  678. * user options
  679. * @return an error string if validation failed
  680. */
  681. _required: function(field, rules, i, options) {
  682. switch (field.prop("type")) {
  683. case "text":
  684. case "password":
  685. case "textarea":
  686. case "file":
  687. case "select-one":
  688. case "select-multiple":
  689. default:
  690. if (! $.trim(field.val()) || field.val() == field.attr("data-validation-placeholder") || field.val() == field.attr("placeholder"))
  691. return options.allrules[rules[i]].alertText;
  692. break;
  693. case "radio":
  694. case "checkbox":
  695. var form = field.closest("form");
  696. var name = field.attr("name");
  697. if (form.find("input[name='" + name + "']:checked").size() == 0)
  698. {
  699. if (form.find("input[name='" + name + "']").size() == 1)
  700. {
  701. return options.allrules[rules[i]].alertTextCheckboxe;
  702. }
  703. else
  704. {
  705. return options.allrules[rules[i]].alertTextCheckboxMultiple;
  706. }
  707. }
  708. break;
  709. }
  710. },
  711. /**
  712. * Validate that 1 from the group field is required
  713. *
  714. * @param {jqObject} field
  715. * @param {Array[String]} rules
  716. * @param {int} i rules index
  717. * @param {Map}
  718. * user options
  719. * @return an error string if validation failed
  720. */
  721. _groupRequired: function(field, rules, i, options) {
  722. var classGroup = "["+options.validateAttribute+"*=" +rules[i + 1] +"]";
  723. var isValid = false;
  724. // Check all fields from the group
  725. field.closest("form").find(classGroup).each(function(){
  726. if(!methods._required($(this), rules, i, options)){
  727. isValid = true;
  728. return false;
  729. }
  730. });
  731. if(!isValid) {
  732. return options.allrules[rules[i]].alertText;
  733. }
  734. },
  735. /**
  736. * Validate rules
  737. *
  738. * @param {jqObject} field
  739. * @param {Array[String]} rules
  740. * @param {int} i rules index
  741. * @param {Map}
  742. * user options
  743. * @return an error string if validation failed
  744. */
  745. _custom: function(field, rules, i, options) {
  746. var customRule = rules[i + 1];
  747. var rule = options.allrules[customRule];
  748. var fn;
  749. if(!rule) {
  750. alert("jqv:custom rule not found - "+customRule);
  751. return;
  752. }
  753. if(rule["regex"]) {
  754. var ex=rule.regex;
  755. if(!ex) {
  756. alert("jqv:custom regex not found - "+customRule);
  757. return;
  758. }
  759. var pattern = new RegExp(ex);
  760. if (!pattern.test(field.val())) return options.allrules[customRule].alertText;
  761. } else if(rule["func"]) {
  762. fn = rule["func"];
  763. if (typeof(fn) !== "function") {
  764. alert("jqv:custom parameter 'function' is no function - "+customRule);
  765. return;
  766. }
  767. if (!fn(field, rules, i, options))
  768. return options.allrules[customRule].alertText;
  769. } else {
  770. alert("jqv:custom type not allowed "+customRule);
  771. return;
  772. }
  773. },
  774. /**
  775. * Validate custom function outside of the engine scope
  776. *
  777. * @param {jqObject} field
  778. * @param {Array[String]} rules
  779. * @param {int} i rules index
  780. * @param {Map}
  781. * user options
  782. * @return an error string if validation failed
  783. */
  784. _funcCall: function(field, rules, i, options) {
  785. var functionName = rules[i + 1];
  786. var fn;
  787. if(functionName.indexOf('.') >-1)
  788. {
  789. var namespaces = functionName.split('.');
  790. var scope = window;
  791. while(namespaces.length)
  792. {
  793. scope = scope[namespaces.shift()];
  794. }
  795. fn = scope;
  796. }
  797. else
  798. fn = window[functionName] || options.customFunctions[functionName];
  799. if (typeof(fn) == 'function')
  800. return fn(field, rules, i, options);
  801. },
  802. /**
  803. * Field match
  804. *
  805. * @param {jqObject} field
  806. * @param {Array[String]} rules
  807. * @param {int} i rules index
  808. * @param {Map}
  809. * user options
  810. * @return an error string if validation failed
  811. */
  812. _equals: function(field, rules, i, options) {
  813. var equalsField = rules[i + 1];
  814. if (field.val() != $("#" + equalsField).val())
  815. return options.allrules.equals.alertText;
  816. },
  817. /**
  818. * Check the maximum size (in characters)
  819. *
  820. * @param {jqObject} field
  821. * @param {Array[String]} rules
  822. * @param {int} i rules index
  823. * @param {Map}
  824. * user options
  825. * @return an error string if validation failed
  826. */
  827. _maxSize: function(field, rules, i, options) {
  828. var max = rules[i + 1];
  829. var len = field.val().length;
  830. if (len > max) {
  831. var rule = options.allrules.maxSize;
  832. //return rule.alertText + max + rule.alertText2;
  833. return rule.alertText + rule.alertText2;
  834. }
  835. },
  836. /**
  837. * Check the minimum size (in characters)
  838. *
  839. * @param {jqObject} field
  840. * @param {Array[String]} rules
  841. * @param {int} i rules index
  842. * @param {Map}
  843. * user options
  844. * @return an error string if validation failed
  845. */
  846. _minSize: function(field, rules, i, options) {
  847. var min = rules[i + 1];
  848. var len = field.val().length;
  849. if (len < min) {
  850. var rule = options.allrules.minSize;
  851. //return rule.alertText + min + rule.alertText2;
  852. return rule.alertText + rule.alertText2;
  853. }
  854. },
  855. /**
  856. * Check number minimum value
  857. *
  858. * @param {jqObject} field
  859. * @param {Array[String]} rules
  860. * @param {int} i rules index
  861. * @param {Map}
  862. * user options
  863. * @return an error string if validation failed
  864. */
  865. _min: function(field, rules, i, options) {
  866. var min = parseFloat(rules[i + 1]);
  867. var len = parseFloat(field.val());
  868. if (len < min) {
  869. var rule = options.allrules.min;
  870. if (rule.alertText2) return rule.alertText + min + rule.alertText2;
  871. return rule.alertText + min;
  872. }
  873. },
  874. /**
  875. * Check number maximum value
  876. *
  877. * @param {jqObject} field
  878. * @param {Array[String]} rules
  879. * @param {int} i rules index
  880. * @param {Map}
  881. * user options
  882. * @return an error string if validation failed
  883. */
  884. _max: function(field, rules, i, options) {
  885. var max = parseFloat(rules[i + 1]);
  886. var len = parseFloat(field.val());
  887. if (len >max ) {
  888. var rule = options.allrules.max;
  889. if (rule.alertText2) return rule.alertText + max + rule.alertText2;
  890. //orefalo: to review, also do the translations
  891. return rule.alertText + max;
  892. }
  893. },
  894. /**
  895. * Checks date is in the past
  896. *
  897. * @param {jqObject} field
  898. * @param {Array[String]} rules
  899. * @param {int} i rules index
  900. * @param {Map}
  901. * user options
  902. * @return an error string if validation failed
  903. */
  904. _past: function(form, field, rules, i, options) {
  905. var p=rules[i + 1];
  906. var fieldAlt = $(form.find("input[name='" + p.replace(/^#+/, '') + "']"));
  907. var pdate;
  908. if (p.toLowerCase() == "now") {
  909. pdate = new Date();
  910. } else if (undefined != fieldAlt.val()) {
  911. if (fieldAlt.is(":disabled"))
  912. return;
  913. pdate = methods._parseDate(fieldAlt.val());
  914. } else {
  915. pdate = methods._parseDate(p);
  916. }
  917. var vdate = methods._parseDate(field.val());
  918. if (vdate > pdate ) {
  919. var rule = options.allrules.past;
  920. if (rule.alertText2) return rule.alertText + methods._dateToString(pdate) + rule.alertText2;
  921. return rule.alertText + methods._dateToString(pdate);
  922. }
  923. },
  924. /**
  925. * Checks date is in the future
  926. *
  927. * @param {jqObject} field
  928. * @param {Array[String]} rules
  929. * @param {int} i rules index
  930. * @param {Map}
  931. * user options
  932. * @return an error string if validation failed
  933. */
  934. _future: function(form, field, rules, i, options) {
  935. var p=rules[i + 1];
  936. var fieldAlt = $(form.find("input[name='" + p.replace(/^#+/, '') + "']"));
  937. var pdate;
  938. if (p.toLowerCase() == "now") {
  939. pdate = new Date();
  940. } else if (undefined != fieldAlt.val()) {
  941. if (fieldAlt.is(":disabled"))
  942. return;
  943. pdate = methods._parseDate(fieldAlt.val());
  944. } else {
  945. pdate = methods._parseDate(p);
  946. }
  947. var vdate = methods._parseDate(field.val());
  948. if (vdate < pdate ) {
  949. var rule = options.allrules.future;
  950. if (rule.alertText2)
  951. return rule.alertText + methods._dateToString(pdate) + rule.alertText2;
  952. return rule.alertText + methods._dateToString(pdate);
  953. }
  954. },
  955. /**
  956. * Checks if valid date
  957. *
  958. * @param {string} date string
  959. * @return a bool based on determination of valid date
  960. */
  961. _isDate: function (value) {
  962. var dateRegEx = new RegExp(/^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$|^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?:(?:0?[1-9]|1[0-2])(\/|-)(?:0?[1-9]|1\d|2[0-8]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(0?2(\/|-)29)(\/|-)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$/);
  963. return dateRegEx.test(value);
  964. },
  965. /**
  966. * Checks if valid date time
  967. *
  968. * @param {string} date string
  969. * @return a bool based on determination of valid date time
  970. */
  971. _isDateTime: function (value){
  972. var dateTimeRegEx = new RegExp(/^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|AM|PM){1}$|^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^((1[012]|0?[1-9]){1}\/(0?[1-9]|[12][0-9]|3[01]){1}\/\d{2,4}\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|AM|PM){1})$/);
  973. return dateTimeRegEx.test(value);
  974. },
  975. //Checks if the start date is before the end date
  976. //returns true if end is later than start
  977. _dateCompare: function (start, end) {
  978. return (new Date(start.toString()) < new Date(end.toString()));
  979. },
  980. /**
  981. * Checks date range
  982. *
  983. * @param {jqObject} first field name
  984. * @param {jqObject} second field name
  985. * @return an error string if validation failed
  986. */
  987. _dateRange: function (field, rules, i, options) {
  988. //are not both populated
  989. if ((!options.firstOfGroup[0].value && options.secondOfGroup[0].value) || (options.firstOfGroup[0].value && !options.secondOfGroup[0].value)) {
  990. return options.allrules[rules[i]].alertText + options.allrules[rules[i]].alertText2;
  991. }
  992. //are not both dates
  993. if (!methods._isDate(options.firstOfGroup[0].value) || !methods._isDate(options.secondOfGroup[0].value)) {
  994. return options.allrules[rules[i]].alertText + options.allrules[rules[i]].alertText2;
  995. }
  996. //are both dates but range is off
  997. if (!methods._dateCompare(options.firstOfGroup[0].value, options.secondOfGroup[0].value)) {
  998. return options.allrules[rules[i]].alertText + options.allrules[rules[i]].alertText2;
  999. }
  1000. },
  1001. /**
  1002. * Checks date time range
  1003. *
  1004. * @param {jqObject} first field name
  1005. * @param {jqObject} second field name
  1006. * @return an error string if validation failed
  1007. */
  1008. _dateTimeRange: function (field, rules, i, options) {
  1009. //are not both populated
  1010. if ((!options.firstOfGroup[0].value && options.secondOfGroup[0].value) || (options.firstOfGroup[0].value && !options.secondOfGroup[0].value)) {
  1011. return options.allrules[rules[i]].alertText + options.allrules[rules[i]].alertText2;
  1012. }
  1013. //are not both dates
  1014. if (!methods._isDateTime(options.firstOfGroup[0].value) || !methods._isDateTime(options.secondOfGroup[0].value)) {
  1015. return options.allrules[rules[i]].alertText + options.allrules[rules[i]].alertText2;
  1016. }
  1017. //are both dates but range is off
  1018. if (!methods._dateCompare(options.firstOfGroup[0].value, options.secondOfGroup[0].value)) {
  1019. return options.allrules[rules[i]].alertText + options.allrules[rules[i]].alertText2;
  1020. }
  1021. },
  1022. /**
  1023. * Max number of checkbox selected
  1024. *
  1025. * @param {jqObject} field
  1026. * @param {Array[String]} rules
  1027. * @param {int} i rules index
  1028. * @param {Map}
  1029. * user options
  1030. * @return an error string if validation failed
  1031. */
  1032. _maxCheckbox: function(form, field, rules, i, options) {
  1033. var nbCheck = rules[i + 1];
  1034. var groupname = field.attr("name");
  1035. var groupSize = form.find("input[name='" + groupname + "']:checked").size();
  1036. if (groupSize > nbCheck) {
  1037. options.showArrow = false;
  1038. if (options.allrules.maxCheckbox.alertText2)
  1039. return options.allrules.maxCheckbox.alertText + " " + nbCheck + " " + options.allrules.maxCheckbox.alertText2;
  1040. return options.allrules.maxCheckbox.alertText;
  1041. }
  1042. },
  1043. /**
  1044. * Min number of checkbox selected
  1045. *
  1046. * @param {jqObject} field
  1047. * @param {Array[String]} rules
  1048. * @param {int} i rules index
  1049. * @param {Map}
  1050. * user options
  1051. * @return an error string if validation failed
  1052. */
  1053. _minCheckbox: function(form, field, rules, i, options) {
  1054. var nbCheck = rules[i + 1];
  1055. var groupname = field.attr("name");
  1056. var groupSize = form.find("input[name='" + groupname + "']:checked").size();
  1057. if (groupSize < nbCheck) {
  1058. options.showArrow = false;
  1059. return options.allrules.minCheckbox.alertText + " " + nbCheck + " " + options.allrules.minCheckbox.alertText2;
  1060. }
  1061. },
  1062. /**
  1063. * Checks that it is a valid credit card number according to the
  1064. * Luhn checksum algorithm.
  1065. *
  1066. * @param {jqObject} field
  1067. * @param {Array[String]} rules
  1068. * @param {int} i rules index
  1069. * @param {Map}
  1070. * user options
  1071. * @return an error string if validation failed
  1072. */
  1073. _creditCard: function(field, rules, i, options) {
  1074. //spaces and dashes may be valid characters, but must be stripped to calculate the checksum.
  1075. var valid = false, cardNumber = field.val().replace(/ +/g, '').replace(/-+/g, '');
  1076. var numDigits = cardNumber.length;
  1077. if (numDigits >= 14 && numDigits <= 16 && parseInt(cardNumber) > 0) {
  1078. var sum = 0, i = numDigits - 1, pos = 1, digit, luhn = new String();
  1079. do {
  1080. digit = parseInt(cardNumber.charAt(i));
  1081. luhn += (pos++ % 2 == 0) ? digit * 2 : digit;
  1082. } while (--i >= 0)
  1083. for (i = 0; i < luhn.length; i++) {
  1084. sum += parseInt(luhn.charAt(i));
  1085. }
  1086. valid = sum % 10 == 0;
  1087. }
  1088. if (!valid) return options.allrules.creditCard.alertText;
  1089. },
  1090. /**
  1091. * Ajax field validation
  1092. *
  1093. * @param {jqObject} field
  1094. * @param {Array[String]} rules
  1095. * @param {int} i rules index
  1096. * @param {Map}
  1097. * user options
  1098. * @return nothing! the ajax validator handles the prompts itself
  1099. */
  1100. _ajax: function(field, rules, i, options) {
  1101. var errorSelector = rules[i + 1];
  1102. var rule = options.allrules[errorSelector];
  1103. var extraData = rule.extraData;
  1104. var extraDataDynamic = rule.extraDataDynamic;
  1105. var data = {
  1106. "fieldId" : field.attr("id"),
  1107. "fieldValue" : field.val()
  1108. };
  1109. if (typeof extraData === "object") {
  1110. $.extend(data, extraData);
  1111. } else if (typeof extraData === "string") {
  1112. var tempData = extraData.split("&");
  1113. for(var i = 0; i < tempData.length; i++) {
  1114. var values = tempData[i].split("=");
  1115. if (values[0] && values[0]) {
  1116. data[values[0]] = values[1];
  1117. }
  1118. }
  1119. }
  1120. if (extraDataDynamic) {
  1121. var tmpData = [];
  1122. var domIds = String(extraDataDynamic).split(",");
  1123. for (var i = 0; i < domIds.length; i++) {
  1124. var id = domIds[i];
  1125. if ($(id).length) {
  1126. var inputValue = field.closest("form").find(id).val();
  1127. var keyValue = id.replace('#', '') + '=' + escape(inputValue);
  1128. data[id.replace('#', '')] = inputValue;
  1129. }
  1130. }
  1131. }
  1132. // If a field change event triggered this we want to clear the cache for this ID
  1133. if (options.eventTrigger == "field") {
  1134. delete(options.ajaxValidCache[field.attr("id")]);
  1135. }
  1136. // If there is an error or if the the field is already validated, do not re-execute AJAX
  1137. if (!options.isError && !methods._checkAjaxFieldStatus(field.attr("id"), options)) {
  1138. $.ajax({
  1139. type: options.ajaxFormValidationMethod,
  1140. url: rule.url,
  1141. cache: false,
  1142. dataType: "json",
  1143. data: data,
  1144. field: field,
  1145. rule: rule,
  1146. methods: methods,
  1147. options: options,
  1148. beforeSend: function() {},
  1149. error: function(data, transport) {
  1150. methods._ajaxError(data, transport);
  1151. },
  1152. success: function(json) {
  1153. // asynchronously called on success, data is the json answer from the server
  1154. var errorFieldId = json[0];
  1155. //var errorField = $($("#" + errorFieldId)[0]);
  1156. var errorField = $($("input[id='" + errorFieldId +"']")[0]);
  1157. // make sure we found the element
  1158. if (errorField.length == 1) {
  1159. var status = json[1];
  1160. // read the optional msg from the server
  1161. var msg = json[2];
  1162. if (!status) {
  1163. // Houston we got a problem - display an red prompt
  1164. options.ajaxValidCache[errorFieldId] = false;
  1165. options.isError = true;
  1166. // resolve the msg prompt
  1167. if(msg) {
  1168. if (options.allrules[msg]) {
  1169. var txt = options.allrules[msg].alertText;
  1170. if (txt) {
  1171. msg = txt;
  1172. }
  1173. }
  1174. }
  1175. else
  1176. msg = rule.alertText;
  1177. methods._showPrompt(errorField, msg, "", true, options);
  1178. } else {
  1179. options.ajaxValidCache[errorFieldId] = true;
  1180. // resolves the msg prompt
  1181. if(msg) {
  1182. if (options.allrules[msg]) {
  1183. var txt = options.allrules[msg].alertTextOk;
  1184. if (txt) {
  1185. msg = txt;
  1186. }
  1187. }
  1188. }
  1189. else
  1190. msg = rule.alertTextOk;
  1191. // see if we should display a green prompt
  1192. if (msg)
  1193. methods._showPrompt(errorField, msg, "pass", true, options);
  1194. else
  1195. methods._closePrompt(errorField);
  1196. // If a submit form triggered this, we want to re-submit the form
  1197. if (options.eventTrigger == "submit")
  1198. field.closest("form").submit();
  1199. }
  1200. }
  1201. errorField.trigger("jqv.field.result", [errorField, options.isError, msg]);
  1202. }
  1203. });
  1204. return rule.alertTextLoad;
  1205. }
  1206. },
  1207. /**
  1208. * Common method to handle ajax errors
  1209. *
  1210. * @param {Object} data
  1211. * @param {Object} transport
  1212. */
  1213. _ajaxError: function(data, transport) {
  1214. if(data.status == 0 && transport == null)
  1215. alert("The page is not served from a server! ajax call failed");
  1216. else if(typeof console != "undefined")
  1217. console.log("Ajax error: " + data.status + " " + transport);
  1218. },
  1219. /**
  1220. * date -> string
  1221. *
  1222. * @param {Object} date
  1223. */
  1224. _dateToString: function(date) {
  1225. return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
  1226. },
  1227. /**
  1228. * Parses an ISO date
  1229. * @param {String} d
  1230. */
  1231. _parseDate: function(d) {
  1232. var dateParts = d.split("-");
  1233. if(dateParts==d)
  1234. dateParts = d.split("/");
  1235. return new Date(dateParts[0], (dateParts[1] - 1) ,dateParts[2]);
  1236. },
  1237. /**
  1238. * Builds or updates a prompt with the given information
  1239. *
  1240. * @param {jqObject} field
  1241. * @param {String} promptText html text to display type
  1242. * @param {String} type the type of bubble: 'pass' (green), 'load' (black) anything else (red)
  1243. * @param {boolean} ajaxed - use to mark fields than being validated with ajax
  1244. * @param {Map} options user options
  1245. */
  1246. _showPrompt: function(field, promptText, type, ajaxed, options, ajaxform) {
  1247. var prompt = methods._getPrompt(field);
  1248. // The ajax submit errors are not see has an error in the form,
  1249. // When the form errors are returned, the engine see 2 bubbles, but those are ebing closed by the engine at the same time
  1250. // Because no error was found befor submitting
  1251. if(ajaxform) prompt = false;
  1252. if(options.promptType == 'diy' && (field.attr('type') == 'text' || field.attr('type') == 'password' || field.attr('type') == 'checkbox'))
  1253. {
  1254. // create the prompt
  1255. var prompt = $('<div>');
  1256. prompt.addClass(methods._getClassName(field.attr("id")) + "formError");
  1257. // add a class name to identify the parent form of the prompt
  1258. prompt.addClass("parentForm"+methods._getClassName(field.parents('form').attr("id")));
  1259. prompt.addClass("error-text");
  1260. prompt.html(promptText);
  1261. field.parent().find('.error-text').remove();
  1262. if(field.parent().attr('style') == 'font-size:16px;')
  1263. {
  1264. if(field.parent().parent().next().attr('class') != 'error-text')
  1265. {
  1266. field.parent().parent().after(prompt);
  1267. }
  1268. }
  1269. else if(field.next().length)
  1270. {
  1271. field.next().after(prompt);
  1272. }
  1273. else
  1274. {
  1275. field.after(prompt);
  1276. }
  1277. switch (type) {
  1278. case "pass":
  1279. prompt.addClass("greenPopup");
  1280. break;
  1281. case "load":
  1282. prompt.addClass("blackPopup");
  1283. break;
  1284. default:
  1285. /* it has error */
  1286. //alert("unknown popup type:"+type);
  1287. }
  1288. if (ajaxed)
  1289. {
  1290. prompt.addClass("ajaxed");
  1291. }
  1292. if(type == 'pass')
  1293. {
  1294. prompt.hide();
  1295. }
  1296. return;
  1297. }
  1298. if (prompt)
  1299. methods._updatePrompt(field, prompt, promptText, type, ajaxed, options);
  1300. else
  1301. methods._buildPrompt(field, promptText, type, ajaxed, options);
  1302. },
  1303. /**
  1304. * Builds and shades a prompt for the given field.
  1305. *
  1306. * @param {jqObject} field
  1307. * @param {String} promptText html text to display type
  1308. * @param {String} type the type of bubble: 'pass' (green), 'load' (black) anything else (red)
  1309. * @param {boolean} ajaxed - use to mark fields than being validated with ajax
  1310. * @param {Map} options user options
  1311. */
  1312. _buildPrompt: function(field, promptText, type, ajaxed, options) {
  1313. // create the prompt
  1314. var prompt = $('<div>');
  1315. prompt.addClass(methods._getClassName(field.attr("id")) + "formError");
  1316. // add a class name to identify the parent form of the prompt
  1317. prompt.addClass("parentForm"+methods._getClassName(field.parents('form').attr("id")));
  1318. prompt.addClass("formError");
  1319. switch (type) {
  1320. case "pass":
  1321. prompt.addClass("greenPopup");
  1322. break;
  1323. case "load":
  1324. prompt.addClass("blackPopup");
  1325. break;
  1326. default:
  1327. /* it has error */
  1328. //alert("unknown popup type:"+type);
  1329. }
  1330. if (ajaxed)
  1331. prompt.addClass("ajaxed");
  1332. // create the prompt content
  1333. var promptContent = $('<div>').addClass("formErrorContent").html(promptText).appendTo(prompt);
  1334. // create the css arrow pointing at the field
  1335. // note that there is no triangle on max-checkbox and radio
  1336. if (options.showArrow) {
  1337. var arrow = $('<div>').addClass("formErrorArrow");
  1338. //prompt positioning adjustment support. Usage: positionType:Xshift,Yshift (for ex.: bottomLeft:+20 or bottomLeft:-20,+10)
  1339. var positionType=field.data("promptPosition") || options.promptPosition;
  1340. if (typeof(positionType)=='string')
  1341. {
  1342. var pos=positionType.indexOf(":");
  1343. if(pos!=-1)
  1344. positionType=positionType.substring(0,pos);
  1345. }
  1346. switch (positionType) {
  1347. case "bottomLeft":
  1348. case "bottomRight":
  1349. prompt.find(".formErrorContent").before(arrow);
  1350. arrow.addClass("formErrorArrowBottom").html('<div class="line1"><!-- --></div><div class="line2"><!-- --></div><div class="line3"><!-- --></div><div class="line4"><!-- --></div><div class="line5"><!-- --></div><div class="line6"><!-- --></div><div class="line7"><!-- --></div><div class="line8"><!-- --></div><div class="line9"><!-- --></div><div class="line10"><!-- --></div>');
  1351. break;
  1352. case "topLeft":
  1353. case "topRight":
  1354. arrow.html('<div class="line10"><!-- --></div><div class="line9"><!-- --></div><div class="line8"><!-- --></div><div class="line7"><!-- --></div><div class="line6"><!-- --></div><div class="line5"><!-- --></div><div class="line4"><!-- --></div><div class="line3"><!-- --></div><div class="line2"><!-- --></div><div class="line1"><!-- --></div>');
  1355. prompt.append(arrow);
  1356. break;
  1357. }
  1358. }
  1359. // Modify z-indexes for jquery ui
  1360. if (field.closest('.ui-dialog').length)
  1361. prompt.addClass('formErrorInsideDialog');
  1362. prompt.css({
  1363. "opacity": 0,
  1364. 'position':'absolute'
  1365. });
  1366. field.before(prompt);
  1367. var pos = methods._calculatePosition(field, prompt, options);
  1368. prompt.css({
  1369. "top": pos.callerTopPosition,
  1370. "left": pos.callerleftPosition,
  1371. "marginTop": pos.marginTopSize,
  1372. "opacity": 0
  1373. }).data("callerField", field);
  1374. if (options.autoHidePrompt) {
  1375. setTimeout(function(){
  1376. prompt.animate({
  1377. "opacity": 0
  1378. },function(){
  1379. prompt.closest('.formErrorOuter').remove();
  1380. prompt.remove();
  1381. });
  1382. }, options.autoHideDelay);
  1383. }
  1384. return prompt.animate({
  1385. "opacity": 0.87
  1386. });
  1387. },
  1388. /**
  1389. * Updates the prompt text field - the field for which the prompt
  1390. * @param {jqObject} field
  1391. * @param {String} promptText html text to display type
  1392. * @param {String} type the type of bubble: 'pass' (green), 'load' (black) anything else (red)
  1393. * @param {boolean} ajaxed - use to mark fields than being validated with ajax
  1394. * @param {Map} options user options
  1395. */
  1396. _updatePrompt: function(field, prompt, promptText, type, ajaxed, options, noAnimation) {
  1397. if (prompt) {
  1398. if (typeof type !== "undefined") {
  1399. if (type == "pass")
  1400. prompt.addClass("greenPopup");
  1401. else
  1402. prompt.removeClass("greenPopup");
  1403. if (type == "load")
  1404. prompt.addClass("blackPopup");
  1405. else
  1406. prompt.removeClass("blackPopup");
  1407. }
  1408. if (ajaxed)
  1409. prompt.addClass("ajaxed");
  1410. else
  1411. prompt.removeClass("ajaxed");
  1412. prompt.find(".formErrorContent").html(promptText);
  1413. var pos = methods._calculatePosition(field, prompt, options);
  1414. var css = {"top": pos.callerTopPosition,
  1415. "left": pos.callerleftPosition,
  1416. "marginTop": pos.marginTopSize};
  1417. if (noAnimation)
  1418. prompt.css(css);
  1419. else
  1420. prompt.animate(css);
  1421. }
  1422. },
  1423. /**
  1424. * Closes the prompt associated with the given field
  1425. *
  1426. * @param {jqObject}
  1427. * field
  1428. */
  1429. _closePrompt: function(field) {
  1430. var prompt = methods._getPrompt(field);
  1431. if (prompt)
  1432. prompt.fadeTo("fast", 0, function() {
  1433. prompt.parent('.formErrorOuter').remove();
  1434. prompt.remove();
  1435. });
  1436. },
  1437. closePrompt: function(field) {
  1438. return methods._closePrompt(field);
  1439. },
  1440. /**
  1441. * Returns the error prompt matching the field if any
  1442. *
  1443. * @param {jqObject}
  1444. * field
  1445. * @return undefined or the error prompt (jqObject)
  1446. */
  1447. _getPrompt: function(field) {
  1448. var formId = $(field).closest('form').attr('id');
  1449. var className = methods._getClassName(field.attr("id")) + "formError";
  1450. var match = $("." + methods._escapeExpression(className) + '.parentForm' + formId)[0];
  1451. if (match)
  1452. return $(match);
  1453. },
  1454. /**
  1455. * Returns the escapade classname
  1456. *
  1457. * @param {selector}
  1458. * className
  1459. */
  1460. _escapeExpression: function (selector) {
  1461. return selector.replace(/([#;&,\.\+\*\~':"\!\^$\[\]\(\)=>\|])/g, "\\$1");
  1462. },
  1463. /**
  1464. * returns true if we are in a RTLed document
  1465. *
  1466. * @param {jqObject} field
  1467. */
  1468. isRTL: function(field)
  1469. {
  1470. var $document = $(document);
  1471. var $body = $('body');
  1472. var rtl =
  1473. (field && field.hasClass('rtl')) ||
  1474. (field && (field.attr('dir') || '').toLowerCase()==='rtl') ||
  1475. $document.hasClass('rtl') ||
  1476. ($document.attr('dir') || '').toLowerCase()==='rtl' ||
  1477. $body.hasClass('rtl') ||
  1478. ($body.attr('dir') || '').toLowerCase()==='rtl';
  1479. return Boolean(rtl);
  1480. },
  1481. /**
  1482. * Calculates prompt position
  1483. *
  1484. * @param {jqObject}
  1485. * field
  1486. * @param {jqObject}
  1487. * the prompt
  1488. * @param {Map}
  1489. * options
  1490. * @return positions
  1491. */
  1492. _calculatePosition: function (field, promptElmt, options) {
  1493. var promptTopPosition, promptleftPosition, marginTopSize;
  1494. var fieldWidth = field.width();
  1495. var fieldLeft = field.position().left;
  1496. var fieldTop = field.position().top;
  1497. var fieldHeight = field.height();
  1498. var promptHeight = promptElmt.height();
  1499. // is the form contained in an overflown container?
  1500. promptTopPosition = promptleftPosition = 0;
  1501. // compensation for the arrow
  1502. marginTopSize = -promptHeight;
  1503. //prompt positioning adjustment support
  1504. //now you can adjust prompt position
  1505. //usage: positionType:Xshift,Yshift
  1506. //for example:
  1507. // bottomLeft:+20 means bottomLeft position shifted by 20 pixels right horizontally
  1508. // topRight:20, -15 means topRight position shifted by 20 pixels to right and 15 pixels to top
  1509. //You can use +pixels, - pixels. If no sign is provided than + is default.
  1510. var positionType=field.data("promptPosition") || options.promptPosition;
  1511. var shift1="";
  1512. var shift2="";
  1513. var shiftX=0;
  1514. var shiftY=0;
  1515. if (typeof(positionType)=='string') {
  1516. //do we have any position adjustments ?
  1517. if (positionType.indexOf(":")!=-1) {
  1518. shift1=positionType.substring(positionType.indexOf(":")+1);
  1519. positionType=positionType.substring(0,positionType.indexOf(":"));
  1520. //if any advanced positioning will be needed (percents or something else) - parser should be added here
  1521. //for now we use simple parseInt()
  1522. //do we have second parameter?
  1523. if (shift1.indexOf(",") !=-1) {
  1524. shift2=shift1.substring(shift1.indexOf(",") +1);
  1525. shift1=shift1.substring(0,shift1.indexOf(","));
  1526. shiftY=parseInt(shift2);
  1527. if (isNaN(shiftY)) shiftY=0;
  1528. };
  1529. shiftX=parseInt(shift1);
  1530. if (isNaN(shift1)) shift1=0;
  1531. };
  1532. };
  1533. switch (positionType) {
  1534. default:
  1535. case "topRight":
  1536. promptleftPosition += fieldLeft + fieldWidth - 30;
  1537. promptTopPosition += fieldTop;
  1538. break;
  1539. case "topLeft":
  1540. promptTopPosition += fieldTop;
  1541. promptleftPosition += fieldLeft;
  1542. break;
  1543. case "centerRight":
  1544. promptTopPosition = fieldTop+4;
  1545. marginTopSize = 0;
  1546. promptleftPosition= fieldLeft + field.outerWidth(true)+5;
  1547. break;
  1548. case "centerLeft":
  1549. promptleftPosition = fieldLeft - (promptElmt.width() + 2);
  1550. promptTopPosition = fieldTop+4;
  1551. marginTopSize = 0;
  1552. break;
  1553. case "bottomLeft":
  1554. promptTopPosition = fieldTop + field.height() + 5;
  1555. marginTopSize = 0;
  1556. promptleftPosition = fieldLeft;
  1557. break;
  1558. case "bottomRight":
  1559. promptleftPosition = fieldLeft + fieldWidth - 30;
  1560. promptTopPosition = fieldTop + field.height() + 5;
  1561. marginTopSize = 0;
  1562. };
  1563. //apply adjusments if any
  1564. promptleftPosition += shiftX;
  1565. promptTopPosition += shiftY;
  1566. return {
  1567. "callerTopPosition": promptTopPosition + "px",
  1568. "callerleftPosition": promptleftPosition + "px",
  1569. "marginTopSize": marginTopSize + "px"
  1570. };
  1571. },
  1572. /**
  1573. * Saves the user options and variables in the form.data
  1574. *
  1575. * @param {jqObject}
  1576. * form - the form where the user option should be saved
  1577. * @param {Map}
  1578. * options - the user options
  1579. * @return the user options (extended from the defaults)
  1580. */
  1581. _saveOptions: function(form, options) {
  1582. // is there a language localisation ?
  1583. if ($.validationEngineLanguage)
  1584. var allRules = $.validationEngineLanguage.allRules;
  1585. else
  1586. $.error("jQuery.validationEngine rules are not loaded, plz add localization files to the page");
  1587. // --- Internals DO NOT TOUCH or OVERLOAD ---
  1588. // validation rules and i18
  1589. $.validationEngine.defaults.allrules = allRules;
  1590. var userOptions = $.extend(true,{},$.validationEngine.defaults,options);
  1591. form.data('jqv', userOptions);
  1592. return userOptions;
  1593. },
  1594. /**
  1595. * Removes forbidden characters from class name
  1596. * @param {String} className
  1597. */
  1598. _getClassName: function(className) {
  1599. if(className)
  1600. return className.replace(/:/g, "_").replace(/\./g, "_");
  1601. },
  1602. /**
  1603. * Conditionally required field
  1604. *
  1605. * @param {jqObject} field
  1606. * @param {Array[String]} rules
  1607. * @param {int} i rules index
  1608. * @param {Map}
  1609. * user options
  1610. * @return an error string if validation failed
  1611. */
  1612. _condRequired: function(field, rules, i, options) {
  1613. var idx, dependingField;
  1614. for(idx = (i + 1); idx < rules.length; idx++) {
  1615. dependingField = jQuery("#" + rules[idx]).first();
  1616. /* Use _required for determining wether dependingField has a value.
  1617. * There is logic there for handling all field types, and default value; so we won't replicate that here
  1618. */
  1619. if (dependingField.length && methods._required(dependingField, ["required"], 0, options) == undefined) {
  1620. /* We now know any of the depending fields has a value,
  1621. * so we can validate this field as per normal required code
  1622. */
  1623. return methods._required(field, ["required"], 0, options);
  1624. }
  1625. }
  1626. }
  1627. };
  1628. /**
  1629. * Plugin entry point.
  1630. * You may pass an action as a parameter or a list of options.
  1631. * if none, the init and attach methods are being called.
  1632. * Remember: if you pass options, the attached method is NOT called automatically
  1633. *
  1634. * @param {String}
  1635. * method (optional) action
  1636. */
  1637. $.fn.validationEngine = function(method) {
  1638. var form = $(this);
  1639. if(!form[0]) return form; // stop here if the form does not exist
  1640. if (typeof(method) == 'string' && method.charAt(0) != '_' && methods[method]) {
  1641. // make sure init is called once
  1642. if(method != "showPrompt" && method != "hide" && method != "hideAll")
  1643. methods.init.apply(form);
  1644. return methods[method].apply(form, Array.prototype.slice.call(arguments, 1));
  1645. } else if (typeof method == 'object' || !method) {
  1646. // default constructor with or without arguments
  1647. methods.init.apply(form, arguments);
  1648. return methods.attach.apply(form);
  1649. } else {
  1650. $.error('Method ' + method + ' does not exist in jQuery.validationEngine');
  1651. }
  1652. };
  1653. // LEAK GLOBAL OPTIONS
  1654. $.validationEngine= {fieldIdCounter: 0,defaults:{
  1655. // Name of the event triggering field validation
  1656. validationEventTrigger: "blur",
  1657. // Automatically scroll viewport to the first error
  1658. scroll: true,
  1659. // Focus on the first input
  1660. focusFirstField:true,
  1661. // Opening box position, possible locations are: topLeft,
  1662. // topRight, bottomLeft, centerRight, bottomRight
  1663. promptPosition: "topRight",
  1664. promptType:'',
  1665. bindMethod:"bind",
  1666. // internal, automatically set to true when it parse a _ajax rule
  1667. inlineAjax: false,
  1668. // if set to true, the form data is sent asynchronously via ajax to the form.action url (get)
  1669. ajaxFormValidation: false,
  1670. // The url to send the submit ajax validation (default to action)
  1671. ajaxFormValidationURL: false,
  1672. // HTTP method used for ajax validation
  1673. ajaxFormValidationMethod: 'get',
  1674. // Ajax form validation callback method: boolean onComplete(form, status, errors, options)
  1675. // retuns false if the form.submit event needs to be canceled.
  1676. onAjaxFormComplete: $.noop,
  1677. // called right before the ajax call, may return false to cancel
  1678. onBeforeAjaxFormValidation: $.noop,
  1679. // Stops form from submitting and execute function assiciated with it
  1680. onValidationComplete: false,
  1681. // Used when you have a form fields too close and the errors messages are on top of other disturbing viewing messages
  1682. doNotShowAllErrosOnSubmit: false,
  1683. // Object where you store custom messages to override the default error messages
  1684. custom_error_messages:{},
  1685. // true if you want to vind the input fields
  1686. binded: true,
  1687. // set to true, when the prompt arrow needs to be displayed
  1688. showArrow: true,
  1689. // did one of the validation fail ? kept global to stop further ajax validations
  1690. isError: false,
  1691. // Caches field validation status, typically only bad status are created.
  1692. // the array is used during ajax form validation to detect issues early and prevent an expensive submit
  1693. ajaxValidCache: {},
  1694. // Auto update prompt position after window resize
  1695. autoPositionUpdate: false,
  1696. InvalidFields: [],
  1697. onSuccess: false,
  1698. onFailure: false,
  1699. // Auto-hide prompt
  1700. autoHidePrompt: false,
  1701. // Delay before auto-hide
  1702. autoHideDelay: 10000,
  1703. // Fade out duration while hiding the validations
  1704. fadeDuration: 0.3,
  1705. // Use Prettify select library
  1706. prettySelect: false,
  1707. // Custom ID uses prefix
  1708. usePrefix: "",
  1709. // Custom ID uses suffix
  1710. useSuffix: "",
  1711. // Only show one message per error prompt
  1712. showOneMessage: false
  1713. }};
  1714. $(function(){$.validationEngine.defaults.promptPosition = methods.isRTL()?'topLeft':"topRight"});
  1715. })(jQuery);