jquery.validationEngine.js 62 KB

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