jquery-validation_dist_jquery__validate.js 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  1. import {
  2. require_jquery
  3. } from "./chunk-DH55I632.js";
  4. import {
  5. __commonJS
  6. } from "./chunk-WFTEJBJX.js";
  7. // node_modules/jquery-validation/dist/jquery.validate.js
  8. var require_jquery_validate = __commonJS({
  9. "node_modules/jquery-validation/dist/jquery.validate.js"(exports, module) {
  10. (function(factory) {
  11. if (typeof define === "function" && define.amd) {
  12. define(["jquery"], factory);
  13. } else if (typeof module === "object" && module.exports) {
  14. module.exports = factory(require_jquery());
  15. } else {
  16. factory(jQuery);
  17. }
  18. })(function($) {
  19. $.extend($.fn, {
  20. // https://jqueryvalidation.org/validate/
  21. validate: function(options) {
  22. if (!this.length) {
  23. if (options && options.debug && window.console) {
  24. console.warn("Nothing selected, can't validate, returning nothing.");
  25. }
  26. return;
  27. }
  28. var validator = $.data(this[0], "validator");
  29. if (validator) {
  30. return validator;
  31. }
  32. this.attr("novalidate", "novalidate");
  33. validator = new $.validator(options, this[0]);
  34. $.data(this[0], "validator", validator);
  35. if (validator.settings.onsubmit) {
  36. this.on("click.validate", ":submit", function(event) {
  37. validator.submitButton = event.currentTarget;
  38. if ($(this).hasClass("cancel")) {
  39. validator.cancelSubmit = true;
  40. }
  41. if ($(this).attr("formnovalidate") !== void 0) {
  42. validator.cancelSubmit = true;
  43. }
  44. });
  45. this.on("submit.validate", function(event) {
  46. if (validator.settings.debug) {
  47. event.preventDefault();
  48. }
  49. function handle() {
  50. var hidden, result;
  51. if (validator.submitButton && (validator.settings.submitHandler || validator.formSubmitted)) {
  52. hidden = $("<input type='hidden'/>").attr("name", validator.submitButton.name).val($(validator.submitButton).val()).appendTo(validator.currentForm);
  53. }
  54. if (validator.settings.submitHandler && !validator.settings.debug) {
  55. result = validator.settings.submitHandler.call(validator, validator.currentForm, event);
  56. if (hidden) {
  57. hidden.remove();
  58. }
  59. if (result !== void 0) {
  60. return result;
  61. }
  62. return false;
  63. }
  64. return true;
  65. }
  66. if (validator.cancelSubmit) {
  67. validator.cancelSubmit = false;
  68. return handle();
  69. }
  70. if (validator.form()) {
  71. if (validator.pendingRequest) {
  72. validator.formSubmitted = true;
  73. return false;
  74. }
  75. return handle();
  76. } else {
  77. validator.focusInvalid();
  78. return false;
  79. }
  80. });
  81. }
  82. return validator;
  83. },
  84. // https://jqueryvalidation.org/valid/
  85. valid: function() {
  86. var valid, validator, errorList;
  87. if ($(this[0]).is("form")) {
  88. valid = this.validate().form();
  89. } else {
  90. errorList = [];
  91. valid = true;
  92. validator = $(this[0].form).validate();
  93. this.each(function() {
  94. valid = validator.element(this) && valid;
  95. if (!valid) {
  96. errorList = errorList.concat(validator.errorList);
  97. }
  98. });
  99. validator.errorList = errorList;
  100. }
  101. return valid;
  102. },
  103. // https://jqueryvalidation.org/rules/
  104. rules: function(command, argument) {
  105. var element = this[0], isContentEditable = typeof this.attr("contenteditable") !== "undefined" && this.attr("contenteditable") !== "false", settings, staticRules, existingRules, data, param, filtered;
  106. if (element == null) {
  107. return;
  108. }
  109. if (!element.form && isContentEditable) {
  110. element.form = this.closest("form")[0];
  111. element.name = this.attr("name");
  112. }
  113. if (element.form == null) {
  114. return;
  115. }
  116. if (command) {
  117. settings = $.data(element.form, "validator").settings;
  118. staticRules = settings.rules;
  119. existingRules = $.validator.staticRules(element);
  120. switch (command) {
  121. case "add":
  122. $.extend(existingRules, $.validator.normalizeRule(argument));
  123. delete existingRules.messages;
  124. staticRules[element.name] = existingRules;
  125. if (argument.messages) {
  126. settings.messages[element.name] = $.extend(settings.messages[element.name], argument.messages);
  127. }
  128. break;
  129. case "remove":
  130. if (!argument) {
  131. delete staticRules[element.name];
  132. return existingRules;
  133. }
  134. filtered = {};
  135. $.each(argument.split(/\s/), function(index, method) {
  136. filtered[method] = existingRules[method];
  137. delete existingRules[method];
  138. });
  139. return filtered;
  140. }
  141. }
  142. data = $.validator.normalizeRules(
  143. $.extend(
  144. {},
  145. $.validator.classRules(element),
  146. $.validator.attributeRules(element),
  147. $.validator.dataRules(element),
  148. $.validator.staticRules(element)
  149. ),
  150. element
  151. );
  152. if (data.required) {
  153. param = data.required;
  154. delete data.required;
  155. data = $.extend({ required: param }, data);
  156. }
  157. if (data.remote) {
  158. param = data.remote;
  159. delete data.remote;
  160. data = $.extend(data, { remote: param });
  161. }
  162. return data;
  163. }
  164. });
  165. var trim = function(str) {
  166. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "");
  167. };
  168. $.extend($.expr.pseudos || $.expr[":"], {
  169. // '|| $.expr[ ":" ]' here enables backwards compatibility to jQuery 1.7. Can be removed when dropping jQ 1.7.x support
  170. // https://jqueryvalidation.org/blank-selector/
  171. blank: function(a) {
  172. return !trim("" + $(a).val());
  173. },
  174. // https://jqueryvalidation.org/filled-selector/
  175. filled: function(a) {
  176. var val = $(a).val();
  177. return val !== null && !!trim("" + val);
  178. },
  179. // https://jqueryvalidation.org/unchecked-selector/
  180. unchecked: function(a) {
  181. return !$(a).prop("checked");
  182. }
  183. });
  184. $.validator = function(options, form) {
  185. this.settings = $.extend(true, {}, $.validator.defaults, options);
  186. this.currentForm = form;
  187. this.init();
  188. };
  189. $.validator.format = function(source, params) {
  190. if (arguments.length === 1) {
  191. return function() {
  192. var args = $.makeArray(arguments);
  193. args.unshift(source);
  194. return $.validator.format.apply(this, args);
  195. };
  196. }
  197. if (params === void 0) {
  198. return source;
  199. }
  200. if (arguments.length > 2 && params.constructor !== Array) {
  201. params = $.makeArray(arguments).slice(1);
  202. }
  203. if (params.constructor !== Array) {
  204. params = [params];
  205. }
  206. $.each(params, function(i, n) {
  207. source = source.replace(new RegExp("\\{" + i + "\\}", "g"), function() {
  208. return n;
  209. });
  210. });
  211. return source;
  212. };
  213. $.extend($.validator, {
  214. defaults: {
  215. messages: {},
  216. groups: {},
  217. rules: {},
  218. errorClass: "error",
  219. pendingClass: "pending",
  220. validClass: "valid",
  221. errorElement: "label",
  222. focusCleanup: false,
  223. focusInvalid: true,
  224. errorContainer: $([]),
  225. errorLabelContainer: $([]),
  226. onsubmit: true,
  227. ignore: ":hidden",
  228. ignoreTitle: false,
  229. customElements: [],
  230. onfocusin: function(element) {
  231. this.lastActive = element;
  232. if (this.settings.focusCleanup) {
  233. if (this.settings.unhighlight) {
  234. this.settings.unhighlight.call(this, element, this.settings.errorClass, this.settings.validClass);
  235. }
  236. this.hideThese(this.errorsFor(element));
  237. }
  238. },
  239. onfocusout: function(element) {
  240. if (!this.checkable(element) && (element.name in this.submitted || !this.optional(element))) {
  241. this.element(element);
  242. }
  243. },
  244. onkeyup: function(element, event) {
  245. var excludedKeys = [
  246. 16,
  247. 17,
  248. 18,
  249. 20,
  250. 35,
  251. 36,
  252. 37,
  253. 38,
  254. 39,
  255. 40,
  256. 45,
  257. 144,
  258. 225
  259. ];
  260. if (event.which === 9 && this.elementValue(element) === "" || $.inArray(event.keyCode, excludedKeys) !== -1) {
  261. return;
  262. } else if (element.name in this.submitted || element.name in this.invalid) {
  263. this.element(element);
  264. }
  265. },
  266. onclick: function(element) {
  267. if (element.name in this.submitted) {
  268. this.element(element);
  269. } else if (element.parentNode.name in this.submitted) {
  270. this.element(element.parentNode);
  271. }
  272. },
  273. highlight: function(element, errorClass, validClass) {
  274. if (element.type === "radio") {
  275. this.findByName(element.name).addClass(errorClass).removeClass(validClass);
  276. } else {
  277. $(element).addClass(errorClass).removeClass(validClass);
  278. }
  279. },
  280. unhighlight: function(element, errorClass, validClass) {
  281. if (element.type === "radio") {
  282. this.findByName(element.name).removeClass(errorClass).addClass(validClass);
  283. } else {
  284. $(element).removeClass(errorClass).addClass(validClass);
  285. }
  286. }
  287. },
  288. // https://jqueryvalidation.org/jQuery.validator.setDefaults/
  289. setDefaults: function(settings) {
  290. $.extend($.validator.defaults, settings);
  291. },
  292. messages: {
  293. required: "This field is required.",
  294. remote: "Please fix this field.",
  295. email: "Please enter a valid email address.",
  296. url: "Please enter a valid URL.",
  297. date: "Please enter a valid date.",
  298. dateISO: "Please enter a valid date (ISO).",
  299. number: "Please enter a valid number.",
  300. digits: "Please enter only digits.",
  301. equalTo: "Please enter the same value again.",
  302. maxlength: $.validator.format("Please enter no more than {0} characters."),
  303. minlength: $.validator.format("Please enter at least {0} characters."),
  304. rangelength: $.validator.format("Please enter a value between {0} and {1} characters long."),
  305. range: $.validator.format("Please enter a value between {0} and {1}."),
  306. max: $.validator.format("Please enter a value less than or equal to {0}."),
  307. min: $.validator.format("Please enter a value greater than or equal to {0}."),
  308. step: $.validator.format("Please enter a multiple of {0}.")
  309. },
  310. autoCreateRanges: false,
  311. prototype: {
  312. init: function() {
  313. this.labelContainer = $(this.settings.errorLabelContainer);
  314. this.errorContext = this.labelContainer.length && this.labelContainer || $(this.currentForm);
  315. this.containers = $(this.settings.errorContainer).add(this.settings.errorLabelContainer);
  316. this.submitted = {};
  317. this.valueCache = {};
  318. this.pendingRequest = 0;
  319. this.pending = {};
  320. this.invalid = {};
  321. this.reset();
  322. var currentForm = this.currentForm, groups = this.groups = {}, rules;
  323. $.each(this.settings.groups, function(key, value) {
  324. if (typeof value === "string") {
  325. value = value.split(/\s/);
  326. }
  327. $.each(value, function(index, name) {
  328. groups[name] = key;
  329. });
  330. });
  331. rules = this.settings.rules;
  332. $.each(rules, function(key, value) {
  333. rules[key] = $.validator.normalizeRule(value);
  334. });
  335. function delegate(event) {
  336. var isContentEditable = typeof $(this).attr("contenteditable") !== "undefined" && $(this).attr("contenteditable") !== "false";
  337. if (!this.form && isContentEditable) {
  338. this.form = $(this).closest("form")[0];
  339. this.name = $(this).attr("name");
  340. }
  341. if (currentForm !== this.form) {
  342. return;
  343. }
  344. var validator = $.data(this.form, "validator"), eventType = "on" + event.type.replace(/^validate/, ""), settings = validator.settings;
  345. if (settings[eventType] && !$(this).is(settings.ignore)) {
  346. settings[eventType].call(validator, this, event);
  347. }
  348. }
  349. var focusListeners = [
  350. ":text",
  351. "[type='password']",
  352. "[type='file']",
  353. "select",
  354. "textarea",
  355. "[type='number']",
  356. "[type='search']",
  357. "[type='tel']",
  358. "[type='url']",
  359. "[type='email']",
  360. "[type='datetime']",
  361. "[type='date']",
  362. "[type='month']",
  363. "[type='week']",
  364. "[type='time']",
  365. "[type='datetime-local']",
  366. "[type='range']",
  367. "[type='color']",
  368. "[type='radio']",
  369. "[type='checkbox']",
  370. "[contenteditable]",
  371. "[type='button']"
  372. ];
  373. var clickListeners = ["select", "option", "[type='radio']", "[type='checkbox']"];
  374. $(this.currentForm).on("focusin.validate focusout.validate keyup.validate", focusListeners.concat(this.settings.customElements).join(", "), delegate).on("click.validate", clickListeners.concat(this.settings.customElements).join(", "), delegate);
  375. if (this.settings.invalidHandler) {
  376. $(this.currentForm).on("invalid-form.validate", this.settings.invalidHandler);
  377. }
  378. },
  379. // https://jqueryvalidation.org/Validator.form/
  380. form: function() {
  381. this.checkForm();
  382. $.extend(this.submitted, this.errorMap);
  383. this.invalid = $.extend({}, this.errorMap);
  384. if (!this.valid()) {
  385. $(this.currentForm).triggerHandler("invalid-form", [this]);
  386. }
  387. this.showErrors();
  388. return this.valid();
  389. },
  390. checkForm: function() {
  391. this.prepareForm();
  392. for (var i = 0, elements = this.currentElements = this.elements(); elements[i]; i++) {
  393. this.check(elements[i]);
  394. }
  395. return this.valid();
  396. },
  397. // https://jqueryvalidation.org/Validator.element/
  398. element: function(element) {
  399. var cleanElement = this.clean(element), checkElement = this.validationTargetFor(cleanElement), v = this, result = true, rs, group;
  400. if (checkElement === void 0) {
  401. delete this.invalid[cleanElement.name];
  402. } else {
  403. this.prepareElement(checkElement);
  404. this.currentElements = $(checkElement);
  405. group = this.groups[checkElement.name];
  406. if (group) {
  407. $.each(this.groups, function(name, testgroup) {
  408. if (testgroup === group && name !== checkElement.name) {
  409. cleanElement = v.validationTargetFor(v.clean(v.findByName(name)));
  410. if (cleanElement && cleanElement.name in v.invalid) {
  411. v.currentElements.push(cleanElement);
  412. result = v.check(cleanElement) && result;
  413. }
  414. }
  415. });
  416. }
  417. rs = this.check(checkElement) !== false;
  418. result = result && rs;
  419. if (rs) {
  420. this.invalid[checkElement.name] = false;
  421. } else {
  422. this.invalid[checkElement.name] = true;
  423. }
  424. if (!this.numberOfInvalids()) {
  425. this.toHide = this.toHide.add(this.containers);
  426. }
  427. this.showErrors();
  428. $(element).attr("aria-invalid", !rs);
  429. }
  430. return result;
  431. },
  432. // https://jqueryvalidation.org/Validator.showErrors/
  433. showErrors: function(errors) {
  434. if (errors) {
  435. var validator = this;
  436. $.extend(this.errorMap, errors);
  437. this.errorList = $.map(this.errorMap, function(message, name) {
  438. return {
  439. message,
  440. element: validator.findByName(name)[0]
  441. };
  442. });
  443. this.successList = $.grep(this.successList, function(element) {
  444. return !(element.name in errors);
  445. });
  446. }
  447. if (this.settings.showErrors) {
  448. this.settings.showErrors.call(this, this.errorMap, this.errorList);
  449. } else {
  450. this.defaultShowErrors();
  451. }
  452. },
  453. // https://jqueryvalidation.org/Validator.resetForm/
  454. resetForm: function() {
  455. if ($.fn.resetForm) {
  456. $(this.currentForm).resetForm();
  457. }
  458. this.invalid = {};
  459. this.submitted = {};
  460. this.prepareForm();
  461. this.hideErrors();
  462. var elements = this.elements().removeData("previousValue").removeAttr("aria-invalid");
  463. this.resetElements(elements);
  464. },
  465. resetElements: function(elements) {
  466. var i;
  467. if (this.settings.unhighlight) {
  468. for (i = 0; elements[i]; i++) {
  469. this.settings.unhighlight.call(
  470. this,
  471. elements[i],
  472. this.settings.errorClass,
  473. ""
  474. );
  475. this.findByName(elements[i].name).removeClass(this.settings.validClass);
  476. }
  477. } else {
  478. elements.removeClass(this.settings.errorClass).removeClass(this.settings.validClass);
  479. }
  480. },
  481. numberOfInvalids: function() {
  482. return this.objectLength(this.invalid);
  483. },
  484. objectLength: function(obj) {
  485. var count = 0, i;
  486. for (i in obj) {
  487. if (obj[i] !== void 0 && obj[i] !== null && obj[i] !== false) {
  488. count++;
  489. }
  490. }
  491. return count;
  492. },
  493. hideErrors: function() {
  494. this.hideThese(this.toHide);
  495. },
  496. hideThese: function(errors) {
  497. errors.not(this.containers).text("");
  498. this.addWrapper(errors).hide();
  499. },
  500. valid: function() {
  501. return this.size() === 0;
  502. },
  503. size: function() {
  504. return this.errorList.length;
  505. },
  506. focusInvalid: function() {
  507. if (this.settings.focusInvalid) {
  508. try {
  509. $(this.findLastActive() || this.errorList.length && this.errorList[0].element || []).filter(":visible").trigger("focus").trigger("focusin");
  510. } catch (e) {
  511. }
  512. }
  513. },
  514. findLastActive: function() {
  515. var lastActive = this.lastActive;
  516. return lastActive && $.grep(this.errorList, function(n) {
  517. return n.element.name === lastActive.name;
  518. }).length === 1 && lastActive;
  519. },
  520. elements: function() {
  521. var validator = this, rulesCache = {}, selectors = ["input", "select", "textarea", "[contenteditable]"];
  522. return $(this.currentForm).find(selectors.concat(this.settings.customElements).join(", ")).not(":submit, :reset, :image, :disabled").not(this.settings.ignore).filter(function() {
  523. var name = this.name || $(this).attr("name");
  524. var isContentEditable = typeof $(this).attr("contenteditable") !== "undefined" && $(this).attr("contenteditable") !== "false";
  525. if (!name && validator.settings.debug && window.console) {
  526. console.error("%o has no name assigned", this);
  527. }
  528. if (isContentEditable) {
  529. this.form = $(this).closest("form")[0];
  530. this.name = name;
  531. }
  532. if (this.form !== validator.currentForm) {
  533. return false;
  534. }
  535. if (name in rulesCache || !validator.objectLength($(this).rules())) {
  536. return false;
  537. }
  538. rulesCache[name] = true;
  539. return true;
  540. });
  541. },
  542. clean: function(selector) {
  543. return $(selector)[0];
  544. },
  545. errors: function() {
  546. var errorClass = this.settings.errorClass.split(" ").join(".");
  547. return $(this.settings.errorElement + "." + errorClass, this.errorContext);
  548. },
  549. resetInternals: function() {
  550. this.successList = [];
  551. this.errorList = [];
  552. this.errorMap = {};
  553. this.toShow = $([]);
  554. this.toHide = $([]);
  555. },
  556. reset: function() {
  557. this.resetInternals();
  558. this.currentElements = $([]);
  559. },
  560. prepareForm: function() {
  561. this.reset();
  562. this.toHide = this.errors().add(this.containers);
  563. },
  564. prepareElement: function(element) {
  565. this.reset();
  566. this.toHide = this.errorsFor(element);
  567. },
  568. elementValue: function(element) {
  569. var $element = $(element), type = element.type, isContentEditable = typeof $element.attr("contenteditable") !== "undefined" && $element.attr("contenteditable") !== "false", val, idx;
  570. if (type === "radio" || type === "checkbox") {
  571. return this.findByName(element.name).filter(":checked").val();
  572. } else if (type === "number" && typeof element.validity !== "undefined") {
  573. return element.validity.badInput ? "NaN" : $element.val();
  574. }
  575. if (isContentEditable) {
  576. val = $element.text();
  577. } else {
  578. val = $element.val();
  579. }
  580. if (type === "file") {
  581. if (val.substr(0, 12) === "C:\\fakepath\\") {
  582. return val.substr(12);
  583. }
  584. idx = val.lastIndexOf("/");
  585. if (idx >= 0) {
  586. return val.substr(idx + 1);
  587. }
  588. idx = val.lastIndexOf("\\");
  589. if (idx >= 0) {
  590. return val.substr(idx + 1);
  591. }
  592. return val;
  593. }
  594. if (typeof val === "string") {
  595. return val.replace(/\r/g, "");
  596. }
  597. return val;
  598. },
  599. check: function(element) {
  600. element = this.validationTargetFor(this.clean(element));
  601. var rules = $(element).rules(), rulesCount = $.map(rules, function(n, i) {
  602. return i;
  603. }).length, dependencyMismatch = false, val = this.elementValue(element), result, method, rule, normalizer;
  604. this.abortRequest(element);
  605. if (typeof rules.normalizer === "function") {
  606. normalizer = rules.normalizer;
  607. } else if (typeof this.settings.normalizer === "function") {
  608. normalizer = this.settings.normalizer;
  609. }
  610. if (normalizer) {
  611. val = normalizer.call(element, val);
  612. delete rules.normalizer;
  613. }
  614. for (method in rules) {
  615. rule = { method, parameters: rules[method] };
  616. try {
  617. result = $.validator.methods[method].call(this, val, element, rule.parameters);
  618. if (result === "dependency-mismatch" && rulesCount === 1) {
  619. dependencyMismatch = true;
  620. continue;
  621. }
  622. dependencyMismatch = false;
  623. if (result === "pending") {
  624. this.toHide = this.toHide.not(this.errorsFor(element));
  625. return;
  626. }
  627. if (!result) {
  628. this.formatAndAdd(element, rule);
  629. return false;
  630. }
  631. } catch (e) {
  632. if (this.settings.debug && window.console) {
  633. console.log("Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method.", e);
  634. }
  635. if (e instanceof TypeError) {
  636. e.message += ". Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method.";
  637. }
  638. throw e;
  639. }
  640. }
  641. if (dependencyMismatch) {
  642. return;
  643. }
  644. if (this.objectLength(rules)) {
  645. this.successList.push(element);
  646. }
  647. return true;
  648. },
  649. // Return the custom message for the given element and validation method
  650. // specified in the element's HTML5 data attribute
  651. // return the generic message if present and no method specific message is present
  652. customDataMessage: function(element, method) {
  653. return $(element).data("msg" + method.charAt(0).toUpperCase() + method.substring(1).toLowerCase()) || $(element).data("msg");
  654. },
  655. // Return the custom message for the given element name and validation method
  656. customMessage: function(name, method) {
  657. var m = this.settings.messages[name];
  658. return m && (m.constructor === String ? m : m[method]);
  659. },
  660. // Return the first defined argument, allowing empty strings
  661. findDefined: function() {
  662. for (var i = 0; i < arguments.length; i++) {
  663. if (arguments[i] !== void 0) {
  664. return arguments[i];
  665. }
  666. }
  667. return void 0;
  668. },
  669. // The second parameter 'rule' used to be a string, and extended to an object literal
  670. // of the following form:
  671. // rule = {
  672. // method: "method name",
  673. // parameters: "the given method parameters"
  674. // }
  675. //
  676. // The old behavior still supported, kept to maintain backward compatibility with
  677. // old code, and will be removed in the next major release.
  678. defaultMessage: function(element, rule) {
  679. if (typeof rule === "string") {
  680. rule = { method: rule };
  681. }
  682. var message = this.findDefined(
  683. this.customMessage(element.name, rule.method),
  684. this.customDataMessage(element, rule.method),
  685. // 'title' is never undefined, so handle empty string as undefined
  686. !this.settings.ignoreTitle && element.title || void 0,
  687. $.validator.messages[rule.method],
  688. "<strong>Warning: No message defined for " + element.name + "</strong>"
  689. ), theregex = /\$?\{(\d+)\}/g;
  690. if (typeof message === "function") {
  691. message = message.call(this, rule.parameters, element);
  692. } else if (theregex.test(message)) {
  693. message = $.validator.format(message.replace(theregex, "{$1}"), rule.parameters);
  694. }
  695. return message;
  696. },
  697. formatAndAdd: function(element, rule) {
  698. var message = this.defaultMessage(element, rule);
  699. this.errorList.push({
  700. message,
  701. element,
  702. method: rule.method
  703. });
  704. this.errorMap[element.name] = message;
  705. this.submitted[element.name] = message;
  706. },
  707. addWrapper: function(toToggle) {
  708. if (this.settings.wrapper) {
  709. toToggle = toToggle.add(toToggle.parent(this.settings.wrapper));
  710. }
  711. return toToggle;
  712. },
  713. defaultShowErrors: function() {
  714. var i, elements, error;
  715. for (i = 0; this.errorList[i]; i++) {
  716. error = this.errorList[i];
  717. if (this.settings.highlight) {
  718. this.settings.highlight.call(this, error.element, this.settings.errorClass, this.settings.validClass);
  719. }
  720. this.showLabel(error.element, error.message);
  721. }
  722. if (this.errorList.length) {
  723. this.toShow = this.toShow.add(this.containers);
  724. }
  725. if (this.settings.success) {
  726. for (i = 0; this.successList[i]; i++) {
  727. this.showLabel(this.successList[i]);
  728. }
  729. }
  730. if (this.settings.unhighlight) {
  731. for (i = 0, elements = this.validElements(); elements[i]; i++) {
  732. this.settings.unhighlight.call(this, elements[i], this.settings.errorClass, this.settings.validClass);
  733. }
  734. }
  735. this.toHide = this.toHide.not(this.toShow);
  736. this.hideErrors();
  737. this.addWrapper(this.toShow).show();
  738. },
  739. validElements: function() {
  740. return this.currentElements.not(this.invalidElements());
  741. },
  742. invalidElements: function() {
  743. return $(this.errorList).map(function() {
  744. return this.element;
  745. });
  746. },
  747. showLabel: function(element, message) {
  748. var place, group, errorID, v, error = this.errorsFor(element), elementID = this.idOrName(element), describedBy = $(element).attr("aria-describedby");
  749. if (error.length) {
  750. error.removeClass(this.settings.validClass).addClass(this.settings.errorClass);
  751. if (this.settings && this.settings.escapeHtml) {
  752. error.text(message || "");
  753. } else {
  754. error.html(message || "");
  755. }
  756. } else {
  757. error = $("<" + this.settings.errorElement + ">").attr("id", elementID + "-error").addClass(this.settings.errorClass);
  758. if (this.settings && this.settings.escapeHtml) {
  759. error.text(message || "");
  760. } else {
  761. error.html(message || "");
  762. }
  763. place = error;
  764. if (this.settings.wrapper) {
  765. place = error.hide().show().wrap("<" + this.settings.wrapper + "/>").parent();
  766. }
  767. if (this.labelContainer.length) {
  768. this.labelContainer.append(place);
  769. } else if (this.settings.errorPlacement) {
  770. this.settings.errorPlacement.call(this, place, $(element));
  771. } else {
  772. place.insertAfter(element);
  773. }
  774. if (error.is("label")) {
  775. error.attr("for", elementID);
  776. } else if (error.parents("label[for='" + this.escapeCssMeta(elementID) + "']").length === 0) {
  777. errorID = error.attr("id");
  778. if (!describedBy) {
  779. describedBy = errorID;
  780. } else if (!describedBy.match(new RegExp("\\b" + this.escapeCssMeta(errorID) + "\\b"))) {
  781. describedBy += " " + errorID;
  782. }
  783. $(element).attr("aria-describedby", describedBy);
  784. group = this.groups[element.name];
  785. if (group) {
  786. v = this;
  787. $.each(v.groups, function(name, testgroup) {
  788. if (testgroup === group) {
  789. $("[name='" + v.escapeCssMeta(name) + "']", v.currentForm).attr("aria-describedby", error.attr("id"));
  790. }
  791. });
  792. }
  793. }
  794. }
  795. if (!message && this.settings.success) {
  796. error.text("");
  797. if (typeof this.settings.success === "string") {
  798. error.addClass(this.settings.success);
  799. } else {
  800. this.settings.success(error, element);
  801. }
  802. }
  803. this.toShow = this.toShow.add(error);
  804. },
  805. errorsFor: function(element) {
  806. var name = this.escapeCssMeta(this.idOrName(element)), describer = $(element).attr("aria-describedby"), selector = "label[for='" + name + "'], label[for='" + name + "'] *";
  807. if (describer) {
  808. selector = selector + ", #" + this.escapeCssMeta(describer).replace(/\s+/g, ", #");
  809. }
  810. return this.errors().filter(selector);
  811. },
  812. // See https://api.jquery.com/category/selectors/, for CSS
  813. // meta-characters that should be escaped in order to be used with JQuery
  814. // as a literal part of a name/id or any selector.
  815. escapeCssMeta: function(string) {
  816. if (string === void 0) {
  817. return "";
  818. }
  819. return string.replace(/([\\!"#$%&'()*+,./:;<=>?@\[\]^`{|}~])/g, "\\$1");
  820. },
  821. idOrName: function(element) {
  822. return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name);
  823. },
  824. validationTargetFor: function(element) {
  825. if (this.checkable(element)) {
  826. element = this.findByName(element.name);
  827. }
  828. return $(element).not(this.settings.ignore)[0];
  829. },
  830. checkable: function(element) {
  831. return /radio|checkbox/i.test(element.type);
  832. },
  833. findByName: function(name) {
  834. return $(this.currentForm).find("[name='" + this.escapeCssMeta(name) + "']");
  835. },
  836. getLength: function(value, element) {
  837. switch (element.nodeName.toLowerCase()) {
  838. case "select":
  839. return $("option:selected", element).length;
  840. case "input":
  841. if (this.checkable(element)) {
  842. return this.findByName(element.name).filter(":checked").length;
  843. }
  844. }
  845. return value.length;
  846. },
  847. depend: function(param, element) {
  848. return this.dependTypes[typeof param] ? this.dependTypes[typeof param](param, element) : true;
  849. },
  850. dependTypes: {
  851. "boolean": function(param) {
  852. return param;
  853. },
  854. "string": function(param, element) {
  855. return !!$(param, element.form).length;
  856. },
  857. "function": function(param, element) {
  858. return param(element);
  859. }
  860. },
  861. optional: function(element) {
  862. var val = this.elementValue(element);
  863. return !$.validator.methods.required.call(this, val, element) && "dependency-mismatch";
  864. },
  865. elementAjaxPort: function(element) {
  866. return "validate" + element.name;
  867. },
  868. startRequest: function(element) {
  869. if (!this.pending[element.name]) {
  870. this.pendingRequest++;
  871. $(element).addClass(this.settings.pendingClass);
  872. this.pending[element.name] = true;
  873. }
  874. },
  875. stopRequest: function(element, valid) {
  876. this.pendingRequest--;
  877. if (this.pendingRequest < 0) {
  878. this.pendingRequest = 0;
  879. }
  880. delete this.pending[element.name];
  881. $(element).removeClass(this.settings.pendingClass);
  882. if (valid && this.pendingRequest === 0 && this.formSubmitted && this.form() && this.pendingRequest === 0) {
  883. $(this.currentForm).trigger("submit");
  884. if (this.submitButton) {
  885. $("input:hidden[name='" + this.submitButton.name + "']", this.currentForm).remove();
  886. }
  887. this.formSubmitted = false;
  888. } else if (!valid && this.pendingRequest === 0 && this.formSubmitted) {
  889. $(this.currentForm).triggerHandler("invalid-form", [this]);
  890. this.formSubmitted = false;
  891. }
  892. },
  893. abortRequest: function(element) {
  894. var port;
  895. if (this.pending[element.name]) {
  896. port = this.elementAjaxPort(element);
  897. $.ajaxAbort(port);
  898. this.pendingRequest--;
  899. if (this.pendingRequest < 0) {
  900. this.pendingRequest = 0;
  901. }
  902. delete this.pending[element.name];
  903. $(element).removeClass(this.settings.pendingClass);
  904. }
  905. },
  906. previousValue: function(element, method) {
  907. method = typeof method === "string" && method || "remote";
  908. return $.data(element, "previousValue") || $.data(element, "previousValue", {
  909. old: null,
  910. valid: true,
  911. message: this.defaultMessage(element, { method })
  912. });
  913. },
  914. // Cleans up all forms and elements, removes validator-specific events
  915. destroy: function() {
  916. this.resetForm();
  917. $(this.currentForm).off(".validate").removeData("validator").find(".validate-equalTo-blur").off(".validate-equalTo").removeClass("validate-equalTo-blur").find(".validate-lessThan-blur").off(".validate-lessThan").removeClass("validate-lessThan-blur").find(".validate-lessThanEqual-blur").off(".validate-lessThanEqual").removeClass("validate-lessThanEqual-blur").find(".validate-greaterThanEqual-blur").off(".validate-greaterThanEqual").removeClass("validate-greaterThanEqual-blur").find(".validate-greaterThan-blur").off(".validate-greaterThan").removeClass("validate-greaterThan-blur");
  918. }
  919. },
  920. classRuleSettings: {
  921. required: { required: true },
  922. email: { email: true },
  923. url: { url: true },
  924. date: { date: true },
  925. dateISO: { dateISO: true },
  926. number: { number: true },
  927. digits: { digits: true },
  928. creditcard: { creditcard: true }
  929. },
  930. addClassRules: function(className, rules) {
  931. if (className.constructor === String) {
  932. this.classRuleSettings[className] = rules;
  933. } else {
  934. $.extend(this.classRuleSettings, className);
  935. }
  936. },
  937. classRules: function(element) {
  938. var rules = {}, classes = $(element).attr("class");
  939. if (classes) {
  940. $.each(classes.split(" "), function() {
  941. if (this in $.validator.classRuleSettings) {
  942. $.extend(rules, $.validator.classRuleSettings[this]);
  943. }
  944. });
  945. }
  946. return rules;
  947. },
  948. normalizeAttributeRule: function(rules, type, method, value) {
  949. if (/min|max|step/.test(method) && (type === null || /number|range|text/.test(type))) {
  950. value = Number(value);
  951. if (isNaN(value)) {
  952. value = void 0;
  953. }
  954. }
  955. if (value || value === 0) {
  956. rules[method] = value;
  957. } else if (type === method && type !== "range") {
  958. rules[type === "date" ? "dateISO" : method] = true;
  959. }
  960. },
  961. attributeRules: function(element) {
  962. var rules = {}, $element = $(element), type = element.getAttribute("type"), method, value;
  963. for (method in $.validator.methods) {
  964. if (method === "required") {
  965. value = element.getAttribute(method);
  966. if (value === "") {
  967. value = true;
  968. }
  969. value = !!value;
  970. } else {
  971. value = $element.attr(method);
  972. }
  973. this.normalizeAttributeRule(rules, type, method, value);
  974. }
  975. if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) {
  976. delete rules.maxlength;
  977. }
  978. return rules;
  979. },
  980. dataRules: function(element) {
  981. var rules = {}, $element = $(element), type = element.getAttribute("type"), method, value;
  982. for (method in $.validator.methods) {
  983. value = $element.data("rule" + method.charAt(0).toUpperCase() + method.substring(1).toLowerCase());
  984. if (value === "") {
  985. value = true;
  986. }
  987. this.normalizeAttributeRule(rules, type, method, value);
  988. }
  989. return rules;
  990. },
  991. staticRules: function(element) {
  992. var rules = {}, validator = $.data(element.form, "validator");
  993. if (validator.settings.rules) {
  994. rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {};
  995. }
  996. return rules;
  997. },
  998. normalizeRules: function(rules, element) {
  999. $.each(rules, function(prop, val) {
  1000. if (val === false) {
  1001. delete rules[prop];
  1002. return;
  1003. }
  1004. if (val.param || val.depends) {
  1005. var keepRule = true;
  1006. switch (typeof val.depends) {
  1007. case "string":
  1008. keepRule = !!$(val.depends, element.form).length;
  1009. break;
  1010. case "function":
  1011. keepRule = val.depends.call(element, element);
  1012. break;
  1013. }
  1014. if (keepRule) {
  1015. rules[prop] = val.param !== void 0 ? val.param : true;
  1016. } else {
  1017. $.data(element.form, "validator").resetElements($(element));
  1018. delete rules[prop];
  1019. }
  1020. }
  1021. });
  1022. $.each(rules, function(rule, parameter) {
  1023. rules[rule] = typeof parameter === "function" && rule !== "normalizer" ? parameter(element) : parameter;
  1024. });
  1025. $.each(["minlength", "maxlength"], function() {
  1026. if (rules[this]) {
  1027. rules[this] = Number(rules[this]);
  1028. }
  1029. });
  1030. $.each(["rangelength", "range"], function() {
  1031. var parts;
  1032. if (rules[this]) {
  1033. if (Array.isArray(rules[this])) {
  1034. rules[this] = [Number(rules[this][0]), Number(rules[this][1])];
  1035. } else if (typeof rules[this] === "string") {
  1036. parts = rules[this].replace(/[\[\]]/g, "").split(/[\s,]+/);
  1037. rules[this] = [Number(parts[0]), Number(parts[1])];
  1038. }
  1039. }
  1040. });
  1041. if ($.validator.autoCreateRanges) {
  1042. if (rules.min != null && rules.max != null) {
  1043. rules.range = [rules.min, rules.max];
  1044. delete rules.min;
  1045. delete rules.max;
  1046. }
  1047. if (rules.minlength != null && rules.maxlength != null) {
  1048. rules.rangelength = [rules.minlength, rules.maxlength];
  1049. delete rules.minlength;
  1050. delete rules.maxlength;
  1051. }
  1052. }
  1053. return rules;
  1054. },
  1055. // Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}
  1056. normalizeRule: function(data) {
  1057. if (typeof data === "string") {
  1058. var transformed = {};
  1059. $.each(data.split(/\s/), function() {
  1060. transformed[this] = true;
  1061. });
  1062. data = transformed;
  1063. }
  1064. return data;
  1065. },
  1066. // https://jqueryvalidation.org/jQuery.validator.addMethod/
  1067. addMethod: function(name, method, message) {
  1068. $.validator.methods[name] = method;
  1069. $.validator.messages[name] = message !== void 0 ? message : $.validator.messages[name];
  1070. if (method.length < 3) {
  1071. $.validator.addClassRules(name, $.validator.normalizeRule(name));
  1072. }
  1073. },
  1074. // https://jqueryvalidation.org/jQuery.validator.methods/
  1075. methods: {
  1076. // https://jqueryvalidation.org/required-method/
  1077. required: function(value, element, param) {
  1078. if (!this.depend(param, element)) {
  1079. return "dependency-mismatch";
  1080. }
  1081. if (element.nodeName.toLowerCase() === "select") {
  1082. var val = $(element).val();
  1083. return val && val.length > 0;
  1084. }
  1085. if (this.checkable(element)) {
  1086. return this.getLength(value, element) > 0;
  1087. }
  1088. return value !== void 0 && value !== null && value.length > 0;
  1089. },
  1090. // https://jqueryvalidation.org/email-method/
  1091. email: function(value, element) {
  1092. return this.optional(element) || /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(value);
  1093. },
  1094. // https://jqueryvalidation.org/url-method/
  1095. url: function(value, element) {
  1096. return this.optional(element) || /^(?:(?:(?:https?|ftp):)?\/\/)(?:(?:[^\]\[?\/<~#`!@$^&*()+=}|:";',>{ ]|%[0-9A-Fa-f]{2})+(?::(?:[^\]\[?\/<~#`!@$^&*()+=}|:";',>{ ]|%[0-9A-Fa-f]{2})*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(value);
  1097. },
  1098. // https://jqueryvalidation.org/date-method/
  1099. date: function() {
  1100. var called = false;
  1101. return function(value, element) {
  1102. if (!called) {
  1103. called = true;
  1104. if (this.settings.debug && window.console) {
  1105. console.warn(
  1106. "The `date` method is deprecated and will be removed in version '2.0.0'.\nPlease don't use it, since it relies on the Date constructor, which\nbehaves very differently across browsers and locales. Use `dateISO`\ninstead or one of the locale specific methods in `localizations/`\nand `additional-methods.js`."
  1107. );
  1108. }
  1109. }
  1110. return this.optional(element) || !/Invalid|NaN/.test(new Date(value).toString());
  1111. };
  1112. }(),
  1113. // https://jqueryvalidation.org/dateISO-method/
  1114. dateISO: function(value, element) {
  1115. return this.optional(element) || /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(value);
  1116. },
  1117. // https://jqueryvalidation.org/number-method/
  1118. number: function(value, element) {
  1119. return this.optional(element) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:-?\.\d+)?$/.test(value);
  1120. },
  1121. // https://jqueryvalidation.org/digits-method/
  1122. digits: function(value, element) {
  1123. return this.optional(element) || /^\d+$/.test(value);
  1124. },
  1125. // https://jqueryvalidation.org/minlength-method/
  1126. minlength: function(value, element, param) {
  1127. var length = Array.isArray(value) ? value.length : this.getLength(value, element);
  1128. return this.optional(element) || length >= param;
  1129. },
  1130. // https://jqueryvalidation.org/maxlength-method/
  1131. maxlength: function(value, element, param) {
  1132. var length = Array.isArray(value) ? value.length : this.getLength(value, element);
  1133. return this.optional(element) || length <= param;
  1134. },
  1135. // https://jqueryvalidation.org/rangelength-method/
  1136. rangelength: function(value, element, param) {
  1137. var length = Array.isArray(value) ? value.length : this.getLength(value, element);
  1138. return this.optional(element) || length >= param[0] && length <= param[1];
  1139. },
  1140. // https://jqueryvalidation.org/min-method/
  1141. min: function(value, element, param) {
  1142. return this.optional(element) || value >= param;
  1143. },
  1144. // https://jqueryvalidation.org/max-method/
  1145. max: function(value, element, param) {
  1146. return this.optional(element) || value <= param;
  1147. },
  1148. // https://jqueryvalidation.org/range-method/
  1149. range: function(value, element, param) {
  1150. return this.optional(element) || value >= param[0] && value <= param[1];
  1151. },
  1152. // https://jqueryvalidation.org/step-method/
  1153. step: function(value, element, param) {
  1154. var type = $(element).attr("type"), errorMessage = "Step attribute on input type " + type + " is not supported.", supportedTypes = ["text", "number", "range"], re = new RegExp("\\b" + type + "\\b"), notSupported = type && !re.test(supportedTypes.join()), decimalPlaces = function(num) {
  1155. var match = ("" + num).match(/(?:\.(\d+))?$/);
  1156. if (!match) {
  1157. return 0;
  1158. }
  1159. return match[1] ? match[1].length : 0;
  1160. }, toInt = function(num) {
  1161. return Math.round(num * Math.pow(10, decimals));
  1162. }, valid = true, decimals;
  1163. if (notSupported) {
  1164. throw new Error(errorMessage);
  1165. }
  1166. decimals = decimalPlaces(param);
  1167. if (decimalPlaces(value) > decimals || toInt(value) % toInt(param) !== 0) {
  1168. valid = false;
  1169. }
  1170. return this.optional(element) || valid;
  1171. },
  1172. // https://jqueryvalidation.org/equalTo-method/
  1173. equalTo: function(value, element, param) {
  1174. var target = $(param);
  1175. if (this.settings.onfocusout && target.not(".validate-equalTo-blur").length) {
  1176. target.addClass("validate-equalTo-blur").on("blur.validate-equalTo", function() {
  1177. $(element).valid();
  1178. });
  1179. }
  1180. return value === target.val();
  1181. },
  1182. // https://jqueryvalidation.org/remote-method/
  1183. remote: function(value, element, param, method) {
  1184. if (this.optional(element)) {
  1185. return "dependency-mismatch";
  1186. }
  1187. method = typeof method === "string" && method || "remote";
  1188. var previous = this.previousValue(element, method), validator, data, optionDataString;
  1189. if (!this.settings.messages[element.name]) {
  1190. this.settings.messages[element.name] = {};
  1191. }
  1192. previous.originalMessage = previous.originalMessage || this.settings.messages[element.name][method];
  1193. this.settings.messages[element.name][method] = previous.message;
  1194. param = typeof param === "string" && { url: param } || param;
  1195. optionDataString = $.param($.extend({ data: value }, param.data));
  1196. if (previous.valid !== null && previous.old === optionDataString) {
  1197. return previous.valid;
  1198. }
  1199. previous.old = optionDataString;
  1200. previous.valid = null;
  1201. validator = this;
  1202. this.startRequest(element);
  1203. data = {};
  1204. data[element.name] = value;
  1205. $.ajax($.extend(true, {
  1206. mode: "abort",
  1207. port: this.elementAjaxPort(element),
  1208. dataType: "json",
  1209. data,
  1210. context: validator.currentForm,
  1211. success: function(response) {
  1212. var valid = response === true || response === "true", errors, message, submitted;
  1213. validator.settings.messages[element.name][method] = previous.originalMessage;
  1214. if (valid) {
  1215. submitted = validator.formSubmitted;
  1216. validator.toHide = validator.errorsFor(element);
  1217. validator.formSubmitted = submitted;
  1218. validator.successList.push(element);
  1219. validator.invalid[element.name] = false;
  1220. validator.showErrors();
  1221. } else {
  1222. errors = {};
  1223. message = response || validator.defaultMessage(element, { method, parameters: value });
  1224. errors[element.name] = previous.message = message;
  1225. validator.invalid[element.name] = true;
  1226. validator.showErrors(errors);
  1227. }
  1228. previous.valid = valid;
  1229. validator.stopRequest(element, valid);
  1230. }
  1231. }, param));
  1232. return "pending";
  1233. }
  1234. }
  1235. });
  1236. var pendingRequests = {}, ajax;
  1237. if ($.ajaxPrefilter) {
  1238. $.ajaxPrefilter(function(settings, _, xhr) {
  1239. var port = settings.port;
  1240. if (settings.mode === "abort") {
  1241. $.ajaxAbort(port);
  1242. pendingRequests[port] = xhr;
  1243. }
  1244. });
  1245. } else {
  1246. ajax = $.ajax;
  1247. $.ajax = function(settings) {
  1248. var mode = ("mode" in settings ? settings : $.ajaxSettings).mode, port = ("port" in settings ? settings : $.ajaxSettings).port;
  1249. if (mode === "abort") {
  1250. $.ajaxAbort(port);
  1251. pendingRequests[port] = ajax.apply(this, arguments);
  1252. return pendingRequests[port];
  1253. }
  1254. return ajax.apply(this, arguments);
  1255. };
  1256. }
  1257. $.ajaxAbort = function(port) {
  1258. if (pendingRequests[port]) {
  1259. pendingRequests[port].abort();
  1260. delete pendingRequests[port];
  1261. }
  1262. };
  1263. return $;
  1264. });
  1265. }
  1266. });
  1267. export default require_jquery_validate();
  1268. /*! Bundled license information:
  1269. jquery-validation/dist/jquery.validate.js:
  1270. (*!
  1271. * jQuery Validation Plugin v1.21.0
  1272. *
  1273. * https://jqueryvalidation.org/
  1274. *
  1275. * Copyright (c) 2024 Jörn Zaefferer
  1276. * Released under the MIT license
  1277. *)
  1278. */
  1279. //# sourceMappingURL=jquery-validation_dist_jquery__validate.js.map