vendor: 50,769 bytes, lines 1-1594
1$.extend( $.fn, { 2 3 4 validate: function( options ) { 5 6 // If nothing is selected, return nothing; can't chain anyway 7 if ( !this.length ) { 8 if ( options && options.debug && window.console ) { 9 console.warn( "Nothing selected, can't validate, returning nothing." ); 10 } 11 return; 12 } 13 14 // Check if a validator for this form was already created 15 var validator = $.data( this[ 0 ], "validator" ); 16 if ( validator ) { 17 return validator; 18 } 19 20 // Add novalidate tag if HTML5. 21 this.attr( "novalidate", "novalidate" ); 22 23 validator = new $.validator( options, this[ 0 ] ); 24 $.data( this[ 0 ], "validator", validator ); 25 26 if ( validator.settings.onsubmit ) { 27 28 this.on( "click.validate", ":submit", function( event ) { 29 30 // Track the used submit button to properly handle scripted 31 // submits later. 32 validator.submitButton = event.currentTarget; 33 34 // Allow suppressing validation by adding a cancel class to the submit button 35 if ( $( this ).hasClass( "cancel" ) ) { 36 validator.cancelSubmit = true; 37 } 38 39 // Allow suppressing validation by adding the html5 formnovalidate attribute to the submit button 40 if ( $( this ).attr( "formnovalidate" ) !== undefined ) { 41 validator.cancelSubmit = true; 42 } 43 } ); 44 45 // Validate the form on submit 46 this.on( "submit.validate", function( event ) { 47 if ( validator.settings.debug ) { 48 49 // Prevent form submit to be able to see console output 50 event.preventDefault(); 51 } 52 53 function handle() { 54 var hidden, result; 55 56 // Insert a hidden input as a replacement for the missing submit button 57 // The hidden input is inserted in two cases: 58 // - A user defined a `submitHandler` 59 // - There was a pending request due to `remote` method and `stopRequest()` 60 // was called to submit the form in case it's valid 61 if ( validator.submitButton && ( validator.settings.submitHandler || validator.formSubmitted ) ) { 62 hidden = $( "<input type='hidden'/>" ) 63 .attr( "name", validator.submitButton.name ) 64 .val( $( validator.submitButton ).val() ) 65 .appendTo( validator.currentForm ); 66 } 67 68 if ( validator.settings.submitHandler && !validator.settings.debug ) { 69 result = validator.settings.submitHandler.call( validator, validator.currentForm, event ); 70 if ( hidden ) { 71 72 // And clean up afterwards; thanks to no-block-scope, hidden can be referenced 73 hidden.remove(); 74 } 75 if ( result !== undefined ) { 76 return result; 77 } 78 return false; 79 } 80 return true; 81 } 82 83 // Prevent submit for invalid forms or custom submit handlers 84 if ( validator.cancelSubmit ) { 85 validator.cancelSubmit = false; 86 return handle(); 87 } 88 if ( validator.form() ) { 89 if ( validator.pendingRequest ) { 90 validator.formSubmitted = true; 91 return false; 92 } 93 return handle(); 94 } else { 95 validator.focusInvalid(); 96 return false; 97 } 98 } ); 99 } 100 101 return validator; 102 }, 103 104 // https://jqueryvalidation.org/valid/ 105 valid: function() { 106 var valid, validator, errorList; 107 108 if ( $( this[ 0 ] ).is( "form" ) ) { 109 valid = this.validate().form(); 110 } else { 111 errorList = []; 112 valid = true; 113 validator = $( this[ 0 ].form ).validate(); 114 this.each( function() { 115 valid = validator.element( this ) && valid; 116 if ( !valid ) { 117 errorList = errorList.concat( validator.errorList ); 118 } 119 } ); 120 validator.errorList = errorList; 121 } 122 return valid; 123 }, 124 125 // https://jqueryvalidation.org/rules/ 126 rules: function( command, argument ) { 127 var element = this[ 0 ], 128 isContentEditable = typeof this.attr( "contenteditable" ) !== "undefined" && this.attr( "contenteditable" ) !== "false", 129 settings, staticRules, existingRules, data, param, filtered; 130 131 // If nothing is selected, return empty object; can't chain anyway 132 if ( element == null ) { 133 return; 134 } 135 136 if ( !element.form && isContentEditable ) { 137 element.form = this.closest( "form" )[ 0 ]; 138 element.name = this.attr( "name" ); 139 } 140 141 if ( element.form == null ) { 142 return; 143 } 144 145 if ( command ) { 146 settings = $.data( element.form, "validator" ).settings; 147 staticRules = settings.rules; 148 existingRules = $.validator.staticRules( element ); 149 switch ( command ) { 150 case "add": 151 $.extend( existingRules, $.validator.normalizeRule( argument ) ); 152 153 // Remove messages from rules, but allow them to be set separately 154 delete existingRules.messages; 155 staticRules[ element.name ] = existingRules; 156 if ( argument.messages ) { 157 settings.messages[ element.name ] = $.extend( settings.messages[ element.name ], argument.messages ); 158 } 159 break; 160 case "remove": 161 if ( !argument ) { 162 delete staticRules[ element.name ]; 163 return existingRules; 164 } 165 filtered = {}; 166 $.each( argument.split( /\s/ ), function( index, method ) { 167 filtered[ method ] = existingRules[ method ]; 168 delete existingRules[ method ]; 169 } ); 170 return filtered; 171 } 172 } 173 174 data = $.validator.normalizeRules( 175 $.extend( 176 {}, 177 $.validator.classRules( element ), 178 $.validator.attributeRules( element ), 179 $.validator.dataRules( element ), 180 $.validator.staticRules( element ) 181 ), element ); 182 183 // Make sure required is at front 184 if ( data.required ) { 185 param = data.required; 186 delete data.required; 187 data = $.extend( { required: param }, data ); 188 } 189 190 // Make sure remote is at back 191 if ( data.remote ) { 192 param = data.remote; 193 delete data.remote; 194 data = $.extend( data, { remote: param } ); 195 } 196 197 return data; 198 } 199} ); 200 201// Custom selectors 202$.extend( $.expr.pseudos || $.expr[ ":" ], { // '|| $.expr[ ":" ]' here enables backwards compatibility to jQuery 1.7. Can be removed when dropping jQ 1.7.x support 203 204 // https://jqueryvalidation.org/blank-selector/ 205 blank: function( a ) { 206 return !$.trim( "" + $( a ).val() ); 207 }, 208 209 // https://jqueryvalidation.org/filled-selector/ 210 filled: function( a ) { 211 var val = $( a ).val(); 212 return val !== null && !!$.trim( "" + val ); 213 }, 214 215 // https://jqueryvalidation.org/unchecked-selector/ 216 unchecked: function( a ) { 217 return !$( a ).prop( "checked" ); 218 } 219} ); 220 221// Constructor for validator 222$.validator = function( options, form ) { 223 this.settings = $.extend( true, {}, $.validator.defaults, options ); 224 this.currentForm = form; 225 this.init(); 226}; 227 228// https://jqueryvalidation.org/jQuery.validator.format/ 229$.validator.format = function( source, params ) { 230 if ( arguments.length === 1 ) { 231 return function() { 232 var args = $.makeArray( arguments ); 233 args.unshift( source ); 234 return $.validator.format.apply( this, args ); 235 }; 236 } 237 if ( params === undefined ) { 238 return source; 239 } 240 if ( arguments.length > 2 && params.constructor !== Array ) { 241 params = $.makeArray( arguments ).slice( 1 ); 242 } 243 if ( params.constructor !== Array ) { 244 params = [ params ]; 245 } 246 $.each( params, function( i, n ) { 247 source = source.replace( new RegExp( "\\{" + i + "\\}", "g" ), function() { 248 return n; 249 } ); 250 } ); 251 return source; 252}; 253 254$.extend( $.validator, { 255 256 defaults: { 257 messages: {}, 258 groups: {}, 259 rules: {}, 260 errorClass: "error", 261 pendingClass: "pending", 262 validClass: "valid", 263 errorElement: "label", 264 focusCleanup: false, 265 focusInvalid: true, 266 errorContainer: $( [] ), 267 errorLabelContainer: $( [] ), 268 onsubmit: true, 269 ignore: ":hidden", 270 ignoreTitle: false, 271 onfocusin: function( element ) { 272 this.lastActive = element; 273 274 // Hide error label and remove error class on focus if enabled 275 if ( this.settings.focusCleanup ) { 276 if ( this.settings.unhighlight ) { 277 this.settings.unhighlight.call( this, element, this.settings.errorClass, this.settings.validClass ); 278 } 279 this.hideThese( this.errorsFor( element ) ); 280 } 281 }, 282 onfocusout: function( element ) { 283 if ( !this.checkable( element ) && ( element.name in this.submitted || !this.optional( element ) ) ) { 284 this.element( element ); 285 } 286 }, 287 onkeyup: function( element, event ) { 288 289 // Avoid revalidate the field when pressing one of the following keys 290 // Shift => 16 291 // Ctrl => 17 292 // Alt => 18 293 // Caps lock => 20 294 // End => 35 295 // Home => 36 296 // Left arrow => 37 297 // Up arrow => 38 298 // Right arrow => 39 299 // Down arrow => 40 300 // Insert => 45 301 // Num lock => 144 302 // AltGr key => 225 303 var excludedKeys = [ 304 16, 17, 18, 20, 35, 36, 37, 305 38, 39, 40, 45, 144, 225 306 ]; 307 308 if ( event.which === 9 && this.elementValue( element ) === "" || $.inArray( event.keyCode, excludedKeys ) !== -1 ) { 309 return; 310 } else if ( element.name in this.submitted || element.name in this.invalid ) { 311 this.element( element ); 312 } 313 }, 314 onclick: function( element ) { 315 316 // Click on selects, radiobuttons and checkboxes 317 if ( element.name in this.submitted ) { 318 this.element( element ); 319 320 // Or option elements, check parent select in that case 321 } else if ( element.parentNode.name in this.submitted ) { 322 this.element( element.parentNode ); 323 } 324 }, 325 highlight: function( element, errorClass, validClass ) { 326 if ( element.type === "radio" ) { 327 this.findByName( element.name ).addClass( errorClass ).removeClass( validClass ); 328 } else { 329 $( element ).addClass( errorClass ).removeClass( validClass ); 330 } 331 }, 332 unhighlight: function( element, errorClass, validClass ) { 333 if ( element.type === "radio" ) { 334 this.findByName( element.name ).removeClass( errorClass ).addClass( validClass ); 335 } else { 336 $( element ).removeClass( errorClass ).addClass( validClass ); 337 } 338 } 339 }, 340 341 // https://jqueryvalidation.org/jQuery.validator.setDefaults/ 342 setDefaults: function( settings ) { 343 $.extend( $.validator.defaults, settings ); 344 }, 345 346 messages: { 347 required: "This field is required.", 348 remote: "Please fix this field.", 349 email: "Please enter a valid email address.", 350 url: "Please enter a valid URL.", 351 date: "Please enter a valid date.", 352 dateISO: "Please enter a valid date (ISO).", 353 number: "Please enter a valid number.", 354 digits: "Please enter only digits.", 355 equalTo: "Please enter the same value again.", 356 maxlength: $.validator.format( "Please enter no more than {0} characters." ), 357 minlength: $.validator.format( "Please enter at least {0} characters." ), 358 rangelength: $.validator.format( "Please enter a value between {0} and {1} characters long." ), 359 range: $.validator.format( "Please enter a value between {0} and {1}." ), 360 max: $.validator.format( "Please enter a value less than or equal to {0}." ), 361 min: $.validator.format( "Please enter a value greater than or equal to {0}." ), 362 step: $.validator.format( "Please enter a multiple of {0}." ) 363 }, 364 365 autoCreateRanges: false, 366 367 prototype: { 368 369 init: function() { 370 this.labelContainer = $( this.settings.errorLabelContainer ); 371 this.errorContext = this.labelContainer.length && this.labelContainer || $( this.currentForm ); 372 this.containers = $( this.settings.errorContainer ).add( this.settings.errorLabelContainer ); 373 this.submitted = {}; 374 this.valueCache = {}; 375 this.pendingRequest = 0; 376 this.pending = {}; 377 this.invalid = {}; 378 this.reset(); 379 380 var currentForm = this.currentForm, 381 groups = ( this.groups = {} ), 382 rules; 383 $.each( this.settings.groups, function( key, value ) { 384 if ( typeof value === "string" ) { 385 value = value.split( /\s/ ); 386 } 387 $.each( value, function( index, name ) { 388 groups[ name ] = key; 389 } ); 390 } ); 391 rules = this.settings.rules; 392 $.each( rules, function( key, value ) { 393 rules[ key ] = $.validator.normalizeRule( value ); 394 } ); 395 396 function delegate( event ) { 397 var isContentEditable = typeof $( this ).attr( "contenteditable" ) !== "undefined" && $( this ).attr( "contenteditable" ) !== "false"; 398 399 // Set form expando on contenteditable 400 if ( !this.form && isContentEditable ) { 401 this.form = $( this ).closest( "form" )[ 0 ]; 402 this.name = $( this ).attr( "name" ); 403 } 404 405 // Ignore the element if it belongs to another form. This will happen mainly 406 // when setting the `form` attribute of an input to the id of another form. 407 if ( currentForm !== this.form ) { 408 return; 409 } 410 411 var validator = $.data( this.form, "validator" ), 412 eventType = "on" + event.type.replace( /^validate/, "" ), 413 settings = validator.settings; 414 if ( settings[ eventType ] && !$( this ).is( settings.ignore ) ) { 415 settings[ eventType ].call( validator, this, event ); 416 } 417 } 418 419 $( this.currentForm ) 420 .on( "focusin.validate focusout.validate keyup.validate", 421 ":text, [type='password'], [type='file'], select, textarea, [type='number'], [type='search'], " + 422 "[type='tel'], [type='url'], [type='email'], [type='datetime'], [type='date'], [type='month'], " + 423 "[type='week'], [type='time'], [type='datetime-local'], [type='range'], [type='color'], " + 424 "[type='radio'], [type='checkbox'], [contenteditable], [type='button']", delegate ) 425 426 // Support: Chrome, oldIE 427 // "select" is provided as event.target when clicking a option 428 .on( "click.validate", "select, option, [type='radio'], [type='checkbox']", delegate ); 429 430 if ( this.settings.invalidHandler ) { 431 $( this.currentForm ).on( "invalid-form.validate", this.settings.invalidHandler ); 432 } 433 }, 434 435 // https://jqueryvalidation.org/Validator.form/ 436 form: function() { 437 this.checkForm(); 438 $.extend( this.submitted, this.errorMap ); 439 this.invalid = $.extend( {}, this.errorMap ); 440 if ( !this.valid() ) { 441 $( this.currentForm ).triggerHandler( "invalid-form", [ this ] ); 442 } 443 this.showErrors(); 444 return this.valid(); 445 }, 446 447 checkForm: function() { 448 this.prepareForm(); 449 for ( var i = 0, elements = ( this.currentElements = this.elements() ); elements[ i ]; i++ ) { 450 this.check( elements[ i ] ); 451 } 452 return this.valid(); 453 }, 454 455 // https://jqueryvalidation.org/Validator.element/ 456 element: function( element ) { 457 var cleanElement = this.clean( element ), 458 checkElement = this.validationTargetFor( cleanElement ), 459 v = this, 460 result = true, 461 rs, group; 462 463 if ( checkElement === undefined ) { 464 delete this.invalid[ cleanElement.name ]; 465 } else { 466 this.prepareElement( checkElement ); 467 this.currentElements = $( checkElement ); 468 469 // If this element is grouped, then validate all group elements already 470 // containing a value 471 group = this.groups[ checkElement.name ]; 472 if ( group ) { 473 $.each( this.groups, function( name, testgroup ) { 474 if ( testgroup === group && name !== checkElement.name ) { 475 cleanElement = v.validationTargetFor( v.clean( v.findByName( name ) ) ); 476 if ( cleanElement && cleanElement.name in v.invalid ) { 477 v.currentElements.push( cleanElement ); 478 result = v.check( cleanElement ) && result; 479 } 480 } 481 } ); 482 } 483 484 rs = this.check( checkElement ) !== false; 485 result = result && rs; 486 if ( rs ) { 487 this.invalid[ checkElement.name ] = false; 488 } else { 489 this.invalid[ checkElement.name ] = true; 490 } 491 492 if ( !this.numberOfInvalids() ) { 493 494 // Hide error containers on last error 495 this.toHide = this.toHide.add( this.containers ); 496 } 497 this.showErrors(); 498 499 // Add aria-invalid status for screen readers 500 $( element ).attr( "aria-invalid", !rs ); 501 } 502 503 return result; 504 }, 505 506 // https://jqueryvalidation.org/Validator.showErrors/ 507 showErrors: function( errors ) { 508 if ( errors ) { 509 var validator = this; 510 511 // Add items to error list and map 512 $.extend( this.errorMap, errors ); 513 this.errorList = $.map( this.errorMap, function( message, name ) { 514 return { 515 message: message, 516 element: validator.findByName( name )[ 0 ] 517 }; 518 } ); 519 520 // Remove items from success list 521 this.successList = $.grep( this.successList, function( element ) { 522 return !( element.name in errors ); 523 } ); 524 } 525 if ( this.settings.showErrors ) { 526 this.settings.showErrors.call( this, this.errorMap, this.errorList ); 527 } else { 528 this.defaultShowErrors(); 529 } 530 }, 531 532 // https://jqueryvalidation.org/Validator.resetForm/ 533 resetForm: function() { 534 if ( $.fn.resetForm ) { 535 $( this.currentForm ).resetForm(); 536 } 537 this.invalid = {}; 538 this.submitted = {}; 539 this.prepareForm(); 540 this.hideErrors(); 541 var elements = this.elements() 542 .removeData( "previousValue" ) 543 .removeAttr( "aria-invalid" ); 544 545 this.resetElements( elements ); 546 }, 547 548 resetElements: function( elements ) { 549 var i; 550 551 if ( this.settings.unhighlight ) { 552 for ( i = 0; elements[ i ]; i++ ) { 553 this.settings.unhighlight.call( this, elements[ i ], 554 this.settings.errorClass, "" ); 555 this.findByName( elements[ i ].name ).removeClass( this.settings.validClass ); 556 } 557 } else { 558 elements 559 .removeClass( this.settings.errorClass ) 560 .removeClass( this.settings.validClass ); 561 } 562 }, 563 564 numberOfInvalids: function() { 565 return this.objectLength( this.invalid ); 566 }, 567 568 objectLength: function( obj ) { 569 /* jshint unused: false */ 570 var count = 0, 571 i; 572 for ( i in obj ) { 573 574 // This check allows counting elements with empty error 575 // message as invalid elements 576 if ( obj[ i ] !== undefined && obj[ i ] !== null && obj[ i ] !== false ) { 577 count++; 578 } 579 } 580 return count; 581 }, 582 583 hideErrors: function() { 584 this.hideThese( this.toHide ); 585 }, 586 587 hideThese: function( errors ) { 588 errors.not( this.containers ).text( "" ); 589 this.addWrapper( errors ).hide(); 590 }, 591 592 valid: function() { 593 return this.size() === 0; 594 }, 595 596 size: function() { 597 return this.errorList.length; 598 }, 599 600 focusInvalid: function() { 601 if ( this.settings.focusInvalid ) { 602 try { 603 $( this.findLastActive() || this.errorList.length && this.errorList[ 0 ].element || [] ) 604 .filter( ":visible" ) 605 .focus() 606 607 // Manually trigger focusin event; without it, focusin handler isn't called, findLastActive won't have anything to find 608 .trigger( "focusin" ); 609 } catch ( e ) { 610 611 // Ignore IE throwing errors when focusing hidden elements 612 } 613 } 614 }, 615 616 findLastActive: function() { 617 var lastActive = this.lastActive; 618 return lastActive && $.grep( this.errorList, function( n ) { 619 return n.element.name === lastActive.name; 620 } ).length === 1 && lastActive; 621 }, 622 623 elements: function() { 624 var validator = this, 625 rulesCache = {}; 626 627 // Select all valid inputs inside the form (no submit or reset buttons) 628 return $( this.currentForm ) 629 .find( "input, select, textarea, [contenteditable]" ) 630 .not( ":submit, :reset, :image, :disabled" ) 631 .not( this.settings.ignore ) 632 .filter( function() { 633 var name = this.name || $( this ).attr( "name" ); // For contenteditable 634 var isContentEditable = typeof $( this ).attr( "contenteditable" ) !== "undefined" && $( this ).attr( "contenteditable" ) !== "false"; 635 636 if ( !name && validator.settings.debug && window.console ) { 637 console.error( "%o has no name assigned", this ); 638 } 639 640 // Set form expando on contenteditable 641 if ( isContentEditable ) { 642 this.form = $( this ).closest( "form" )[ 0 ]; 643 this.name = name; 644 } 645 646 // Ignore elements that belong to other/nested forms 647 if ( this.form !== validator.currentForm ) { 648 return false; 649 } 650 651 // Select only the first element for each name, and only those with rules specified 652 if ( name in rulesCache || !validator.objectLength( $( this ).rules() ) ) { 653 return false; 654 } 655 656 rulesCache[ name ] = true; 657 return true; 658 } ); 659 }, 660 661 clean: function( selector ) { 662 return $( selector )[ 0 ]; 663 }, 664 665 errors: function() { 666 var errorClass = this.settings.errorClass.split( " " ).join( "." ); 667 return $( this.settings.errorElement + "." + errorClass, this.errorContext ); 668 }, 669 670 resetInternals: function() { 671 this.successList = []; 672 this.errorList = []; 673 this.errorMap = {}; 674 this.toShow = $( [] ); 675 this.toHide = $( [] ); 676 }, 677 678 reset: function() { 679 this.resetInternals(); 680 this.currentElements = $( [] ); 681 }, 682 683 prepareForm: function() { 684 this.reset(); 685 this.toHide = this.errors().add( this.containers ); 686 }, 687 688 prepareElement: function( element ) { 689 this.reset(); 690 this.toHide = this.errorsFor( element ); 691 }, 692 693 elementValue: function( element ) { 694 var $element = $( element ), 695 type = element.type, 696 isContentEditable = typeof $element.attr( "contenteditable" ) !== "undefined" && $element.attr( "contenteditable" ) !== "false", 697 val, idx; 698 699 if ( type === "radio" || type === "checkbox" ) { 700 return this.findByName( element.name ).filter( ":checked" ).val(); 701 } else if ( type === "number" && typeof element.validity !== "undefined" ) { 702 return element.validity.badInput ? "NaN" : $element.val(); 703 } 704 705 if ( isContentEditable ) { 706 val = $element.text(); 707 } else { 708 val = $element.val(); 709 } 710 711 if ( type === "file" ) { 712 713 // Modern browser (chrome & safari) 714 if ( val.substr( 0, 12 ) === "C:\\fakepath\\" ) { 715 return val.substr( 12 ); 716 } 717 718 // Legacy browsers 719 // Unix-based path 720 idx = val.lastIndexOf( "/" ); 721 if ( idx >= 0 ) { 722 return val.substr( idx + 1 ); 723 } 724 725 // Windows-based path 726 idx = val.lastIndexOf( "\\" ); 727 if ( idx >= 0 ) { 728 return val.substr( idx + 1 ); 729 } 730 731 // Just the file name 732 return val; 733 } 734 735 if ( typeof val === "string" ) { 736 return val.replace( /\r/g, "" ); 737 } 738 return val; 739 }, 740 741 check: function( element ) { 742 element = this.validationTargetFor( this.clean( element ) ); 743 744 var rules = $( element ).rules(), 745 rulesCount = $.map( rules, function( n, i ) { 746 return i; 747 } ).length, 748 dependencyMismatch = false, 749 val = this.elementValue( element ), 750 result, method, rule, normalizer; 751 752 // Prioritize the local normalizer defined for this element over the global one 753 // if the former exists, otherwise user the global one in case it exists. 754 if ( typeof rules.normalizer === "function" ) { 755 normalizer = rules.normalizer; 756 } else if ( typeof this.settings.normalizer === "function" ) { 757 normalizer = this.settings.normalizer; 758 } 759 760 // If normalizer is defined, then call it to retreive the changed value instead 761 // of using the real one. 762 // Note that `this` in the normalizer is `element`. 763 if ( normalizer ) { 764 val = normalizer.call( element, val ); 765 766 // Delete the normalizer from rules to avoid treating it as a pre-defined method. 767 delete rules.normalizer; 768 } 769 770 for ( method in rules ) { 771 rule = { method: method, parameters: rules[ method ] }; 772 try { 773 result = $.validator.methods[ method ].call( this, val, element, rule.parameters ); 774 775 // If a method indicates that the field is optional and therefore valid, 776 // don't mark it as valid when there are no other rules 777 if ( result === "dependency-mismatch" && rulesCount === 1 ) { 778 dependencyMismatch = true; 779 continue; 780 } 781 dependencyMismatch = false; 782 783 if ( result === "pending" ) { 784 this.toHide = this.toHide.not( this.errorsFor( element ) ); 785 return; 786 } 787 788 if ( !result ) { 789 this.formatAndAdd( element, rule ); 790 return false; 791 } 792 } catch ( e ) { 793 if ( this.settings.debug && window.console ) { 794 console.log( "Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method.", e ); 795 } 796 if ( e instanceof TypeError ) { 797 e.message += ". Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method."; 798 } 799 800 throw e; 801 } 802 } 803 if ( dependencyMismatch ) { 804 return; 805 } 806 if ( this.objectLength( rules ) ) { 807 this.successList.push( element ); 808 } 809 return true; 810 }, 811 812 // Return the custom message for the given element and validation method 813 // specified in the element's HTML5 data attribute 814 // return the generic message if present and no method specific message is present 815 customDataMessage: function( element, method ) { 816 return $( element ).data( "msg" + method.charAt( 0 ).toUpperCase() + 817 method.substring( 1 ).toLowerCase() ) || $( element ).data( "msg" ); 818 }, 819 820 // Return the custom message for the given element name and validation method 821 customMessage: function( name, method ) { 822 var m = this.settings.messages[ name ]; 823 return m && ( m.constructor === String ? m : m[ method ] ); 824 }, 825 826 // Return the first defined argument, allowing empty strings 827 findDefined: function() { 828 for ( var i = 0; i < arguments.length; i++ ) { 829 if ( arguments[ i ] !== undefined ) { 830 return arguments[ i ]; 831 } 832 } 833 return undefined; 834 }, 835 836 // The second parameter 'rule' used to be a string, and extended to an object literal 837 // of the following form: 838 // rule = { 839 // method: "method name", 840 // parameters: "the given method parameters" 841 // } 842 // 843 // The old behavior still supported, kept to maintain backward compatibility with 844 // old code, and will be removed in the next major release. 845 defaultMessage: function( element, rule ) { 846 if ( typeof rule === "string" ) { 847 rule = { method: rule }; 848 } 849 850 var message = this.findDefined( 851 this.customMessage( element.name, rule.method ), 852 this.customDataMessage( element, rule.method ), 853 854 // 'title' is never undefined, so handle empty string as undefined 855 !this.settings.ignoreTitle && element.title || undefined, 856 $.validator.messages[ rule.method ], 857 "<strong>Warning: No message defined for " + element.name + "</strong>" 858 ), 859 theregex = /\$?\{(\d+)\}/g; 860 if ( typeof message === "function" ) { 861 message = message.call( this, rule.parameters, element ); 862 } else if ( theregex.test( message ) ) { 863 message = $.validator.format( message.replace( theregex, "{$1}" ), rule.parameters ); 864 } 865 866 return message; 867 }, 868 869 formatAndAdd: function( element, rule ) { 870 var message = this.defaultMessage( element, rule ); 871 872 this.errorList.push( { 873 message: message, 874 element: element, 875 method: rule.method 876 } ); 877 878 this.errorMap[ element.name ] = message; 879 this.submitted[ element.name ] = message; 880 }, 881 882 addWrapper: function( toToggle ) { 883 if ( this.settings.wrapper ) { 884 toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) ); 885 } 886 return toToggle; 887 }, 888 889 defaultShowErrors: function() { 890 var i, elements, error; 891 for ( i = 0; this.errorList[ i ]; i++ ) { 892 error = this.errorList[ i ]; 893 if ( this.settings.highlight ) { 894 this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.validClass ); 895 } 896 this.showLabel( error.element, error.message ); 897 } 898 if ( this.errorList.length ) { 899 this.toShow = this.toShow.add( this.containers ); 900 } 901 if ( this.settings.success ) { 902 for ( i = 0; this.successList[ i ]; i++ ) { 903 this.showLabel( this.successList[ i ] ); 904 } 905 } 906 if ( this.settings.unhighlight ) { 907 for ( i = 0, elements = this.validElements(); elements[ i ]; i++ ) { 908 this.settings.unhighlight.call( this, elements[ i ], this.settings.errorClass, this.settings.validClass ); 909 } 910 } 911 this.toHide = this.toHide.not( this.toShow ); 912 this.hideErrors(); 913 this.addWrapper( this.toShow ).show(); 914 }, 915 916 validElements: function() { 917 return this.currentElements.not( this.invalidElements() ); 918 }, 919 920 invalidElements: function() { 921 return $( this.errorList ).map( function() { 922 return this.element; 923 } ); 924 }, 925 926 showLabel: function( element, message ) { 927 var place, group, errorID, v, 928 error = this.errorsFor( element ), 929 elementID = this.idOrName( element ), 930 describedBy = $( element ).attr( "aria-describedby" ); 931 932 if ( error.length ) { 933 934 // Refresh error/success class 935 error.removeClass( this.settings.validClass ).addClass( this.settings.errorClass ); 936 937 // Replace message on existing label 938 error.html( message ); 939 } else { 940 941 // Create error element 942 error = $( "<" + this.settings.errorElement + ">" ) 943 .attr( "id", elementID + "-error" ) 944 .addClass( this.settings.errorClass ) 945 .html( message || "" ); 946 947 // Maintain reference to the element to be placed into the DOM 948 place = error; 949 if ( this.settings.wrapper ) { 950 951 // Make sure the element is visible, even in IE 952 // actually showing the wrapped element is handled elsewhere 953 place = error.hide().show().wrap( "<" + this.settings.wrapper + "/>" ).parent(); 954 } 955 if ( this.labelContainer.length ) { 956 this.labelContainer.append( place ); 957 } else if ( this.settings.errorPlacement ) { 958 this.settings.errorPlacement.call( this, place, $( element ) ); 959 } else { 960 place.insertAfter( element ); 961 } 962 963 // Link error back to the element 964 if ( error.is( "label" ) ) { 965 966 // If the error is a label, then associate using 'for' 967 error.attr( "for", elementID ); 968 969 // If the element is not a child of an associated label, then it's necessary 970 // to explicitly apply aria-describedby 971 } else if ( error.parents( "label[for='" + this.escapeCssMeta( elementID ) + "']" ).length === 0 ) { 972 errorID = error.attr( "id" ); 973 974 // Respect existing non-error aria-describedby 975 if ( !describedBy ) { 976 describedBy = errorID; 977 } else if ( !describedBy.match( new RegExp( "\\b" + this.escapeCssMeta( errorID ) + "\\b" ) ) ) { 978 979 // Add to end of list if not already present 980 describedBy += " " + errorID; 981 } 982 $( element ).attr( "aria-describedby", describedBy ); 983 984 // If this element is grouped, then assign to all elements in the same group 985 group = this.groups[ element.name ]; 986 if ( group ) { 987 v = this; 988 $.each( v.groups, function( name, testgroup ) { 989 if ( testgroup === group ) { 990 $( "[name='" + v.escapeCssMeta( name ) + "']", v.currentForm ) 991 .attr( "aria-describedby", error.attr( "id" ) ); 992 } 993 } ); 994 } 995 } 996 } 997 if ( !message && this.settings.success ) { 998 error.text( "" ); 999 if ( typeof this.settings.success === "string" ) { 1000 error.addClass( this.settings.success ); 1001 } else { 1002 this.settings.success( error, element ); 1003 } 1004 } 1005 this.toShow = this.toShow.add( error ); 1006 }, 1007 1008 errorsFor: function( element ) { 1009 var name = this.escapeCssMeta( this.idOrName( element ) ), 1010 describer = $( element ).attr( "aria-describedby" ), 1011 selector = "label[for='" + name + "'], label[for='" + name + "'] *"; 1012 1013 // 'aria-describedby' should directly reference the error element 1014 if ( describer ) { 1015 selector = selector + ", #" + this.escapeCssMeta( describer ) 1016 .replace( /\s+/g, ", #" ); 1017 } 1018 1019 return this 1020 .errors() 1021 .filter( selector ); 1022 }, 1023 1024 // See https://api.jquery.com/category/selectors/, for CSS 1025 // meta-characters that should be escaped in order to be used with JQuery 1026 // as a literal part of a name/id or any selector. 1027 escapeCssMeta: function( string ) { 1028 return string.replace( /([\\!"#$%&'()*+,./:;<=>?@\[\]^`{|}~])/g, "\\$1" ); 1029 }, 1030 1031 idOrName: function( element ) { 1032 return this.groups[ element.name ] || ( this.checkable( element ) ? element.name : element.id || element.name ); 1033 }, 1034 1035 validationTargetFor: function( element ) { 1036 1037 // If radio/checkbox, validate first element in group instead 1038 if ( this.checkable( element ) ) { 1039 element = this.findByName( element.name ); 1040 } 1041 1042 // Always apply ignore filter 1043 return $( element ).not( this.settings.ignore )[ 0 ]; 1044 }, 1045 1046 checkable: function( element ) { 1047 return ( /radio|checkbox/i ).test( element.type ); 1048 }, 1049 1050 findByName: function( name ) { 1051 return $( this.currentForm ).find( "[name='" + this.escapeCssMeta( name ) + "']" ); 1052 }, 1053 1054 getLength: function( value, element ) { 1055 switch ( element.nodeName.toLowerCase() ) { 1056 case "select": 1057 return $( "option:selected", element ).length; 1058 case "input": 1059 if ( this.checkable( element ) ) { 1060 return this.findByName( element.name ).filter( ":checked" ).length; 1061 } 1062 } 1063 return value.length; 1064 }, 1065 1066 depend: function( param, element ) { 1067 return this.dependTypes[ typeof param ] ? this.dependTypes[ typeof param ]( param, element ) : true; 1068 }, 1069 1070 dependTypes: { 1071 "boolean": function( param ) { 1072 return param; 1073 }, 1074 "string": function( param, element ) { 1075 return !!$( param, element.form ).length; 1076 }, 1077 "function": function( param, element ) { 1078 return param( element ); 1079 } 1080 }, 1081 1082 optional: function( element ) { 1083 var val = this.elementValue( element ); 1084 return !$.validator.methods.required.call( this, val, element ) && "dependency-mismatch"; 1085 }, 1086 1087 startRequest: function( element ) { 1088 if ( !this.pending[ element.name ] ) { 1089 this.pendingRequest++; 1090 $( element ).addClass( this.settings.pendingClass ); 1091 this.pending[ element.name ] = true; 1092 } 1093 }, 1094 1095 stopRequest: function( element, valid ) { 1096 this.pendingRequest--; 1097 1098 // Sometimes synchronization fails, make sure pendingRequest is never < 0 1099 if ( this.pendingRequest < 0 ) { 1100 this.pendingRequest = 0; 1101 } 1102 delete this.pending[ element.name ]; 1103 $( element ).removeClass( this.settings.pendingClass ); 1104 if ( valid && this.pendingRequest === 0 && this.formSubmitted && this.form() ) { 1105 $( this.currentForm ).submit(); 1106 1107 // Remove the hidden input that was used as a replacement for the 1108 // missing submit button. The hidden input is added by `handle()` 1109 // to ensure that the value of the used submit button is passed on 1110 // for scripted submits triggered by this method 1111 if ( this.submitButton ) { 1112 $( "input:hidden[name='" + this.submitButton.name + "']", this.currentForm ).remove(); 1113 } 1114 1115 this.formSubmitted = false; 1116 } else if ( !valid && this.pendingRequest === 0 && this.formSubmitted ) { 1117 $( this.currentForm ).triggerHandler( "invalid-form", [ this ] ); 1118 this.formSubmitted = false; 1119 } 1120 }, 1121 1122 previousValue: function( element, method ) { 1123 method = typeof method === "string" && method || "remote"; 1124 1125 return $.data( element, "previousValue" ) || $.data( element, "previousValue", { 1126 old: null, 1127 valid: true, 1128 message: this.defaultMessage( element, { method: method } ) 1129 } ); 1130 }, 1131 1132 // Cleans up all forms and elements, removes validator-specific events 1133 destroy: function() { 1134 this.resetForm(); 1135 1136 $( this.currentForm ) 1137 .off( ".validate" ) 1138 .removeData( "validator" ) 1139 .find( ".validate-equalTo-blur" ) 1140 .off( ".validate-equalTo" ) 1141 .removeClass( "validate-equalTo-blur" ) 1142 .find( ".validate-lessThan-blur" ) 1143 .off( ".validate-lessThan" ) 1144 .removeClass( "validate-lessThan-blur" ) 1145 .find( ".validate-lessThanEqual-blur" ) 1146 .off( ".validate-lessThanEqual" ) 1147 .removeClass( "validate-lessThanEqual-blur" ) 1148 .find( ".validate-greaterThanEqual-blur" ) 1149 .off( ".validate-greaterThanEqual" ) 1150 .removeClass( "validate-greaterThanEqual-blur" ) 1151 .find( ".validate-greaterThan-blur" ) 1152 .off( ".validate-greaterThan" ) 1153 .removeClass( "validate-greaterThan-blur" ); 1154 } 1155 1156 }, 1157 1158 classRuleSettings: { 1159 required: { required: true }, 1160 email: { email: true }, 1161 url: { url: true }, 1162 date: { date: true }, 1163 dateISO: { dateISO: true }, 1164 number: { number: true }, 1165 digits: { digits: true }, 1166 creditcard: { creditcard: true } 1167 }, 1168 1169 addClassRules: function( className, rules ) { 1170 if ( className.constructor === String ) { 1171 this.classRuleSettings[ className ] = rules; 1172 } else { 1173 $.extend( this.classRuleSettings, className ); 1174 } 1175 }, 1176 1177 classRules: function( element ) { 1178 var rules = {}, 1179 classes = $( element ).attr( "class" ); 1180 1181 if ( classes ) { 1182 $.each( classes.split( " " ), function() { 1183 if ( this in $.validator.classRuleSettings ) { 1184 $.extend( rules, $.validator.classRuleSettings[ this ] ); 1185 } 1186 } ); 1187 } 1188 return rules; 1189 }, 1190 1191 normalizeAttributeRule: function( rules, type, method, value ) { 1192 1193 // Convert the value to a number for number inputs, and for text for backwards compability 1194 // allows type="date" and others to be compared as strings 1195 if ( /min|max|step/.test( method ) && ( type === null || /number|range|text/.test( type ) ) ) { 1196 value = Number( value ); 1197 1198 // Support Opera Mini, which returns NaN for undefined minlength 1199 if ( isNaN( value ) ) { 1200 value = undefined; 1201 } 1202 } 1203 1204 if ( value || value === 0 ) { 1205 rules[ method ] = value; 1206 } else if ( type === method && type !== "range" ) { 1207 1208 // Exception: the jquery validate 'range' method 1209 // does not test for the html5 'range' type 1210 rules[ method ] = true; 1211 } 1212 }, 1213 1214 attributeRules: function( element ) { 1215 var rules = {}, 1216 $element = $( element ), 1217 type = element.getAttribute( "type" ), 1218 method, value; 1219 1220 for ( method in $.validator.methods ) { 1221 1222 // Support for <input required> in both html5 and older browsers 1223 if ( method === "required" ) { 1224 value = element.getAttribute( method ); 1225 1226 // Some browsers return an empty string for the required attribute 1227 // and non-HTML5 browsers might have required="" markup 1228 if ( value === "" ) { 1229 value = true; 1230 } 1231 1232 // Force non-HTML5 browsers to return bool 1233 value = !!value; 1234 } else { 1235 value = $element.attr( method ); 1236 } 1237 1238 this.normalizeAttributeRule( rules, type, method, value ); 1239 } 1240 1241 // 'maxlength' may be returned as -1, 2147483647 ( IE ) and 524288 ( safari ) for text inputs 1242 if ( rules.maxlength && /-1|2147483647|524288/.test( rules.maxlength ) ) { 1243 delete rules.maxlength; 1244 } 1245 1246 return rules; 1247 }, 1248 1249 dataRules: function( element ) { 1250 var rules = {}, 1251 $element = $( element ), 1252 type = element.getAttribute( "type" ), 1253 method, value; 1254 1255 for ( method in $.validator.methods ) { 1256 value = $element.data( "rule" + method.charAt( 0 ).toUpperCase() + method.substring( 1 ).toLowerCase() ); 1257 1258 // Cast empty attributes like `data-rule-required` to `true` 1259 if ( value === "" ) { 1260 value = true; 1261 } 1262 1263 this.normalizeAttributeRule( rules, type, method, value ); 1264 } 1265 return rules; 1266 }, 1267 1268 staticRules: function( element ) { 1269 var rules = {}, 1270 validator = $.data( element.form, "validator" ); 1271 1272 if ( validator.settings.rules ) { 1273 rules = $.validator.normalizeRule( validator.settings.rules[ element.name ] ) || {}; 1274 } 1275 return rules; 1276 }, 1277 1278 normalizeRules: function( rules, element ) { 1279 1280 // Handle dependency check 1281 $.each( rules, function( prop, val ) { 1282 1283 // Ignore rule when param is explicitly false, eg. required:false 1284 if ( val === false ) { 1285 delete rules[ prop ]; 1286 return; 1287 } 1288 if ( val.param || val.depends ) { 1289 var keepRule = true; 1290 switch ( typeof val.depends ) { 1291 case "string": 1292 keepRule = !!$( val.depends, element.form ).length; 1293 break; 1294 case "function": 1295 keepRule = val.depends.call( element, element ); 1296 break; 1297 } 1298 if ( keepRule ) { 1299 rules[ prop ] = val.param !== undefined ? val.param : true; 1300 } else { 1301 $.data( element.form, "validator" ).resetElements( $( element ) ); 1302 delete rules[ prop ]; 1303 } 1304 } 1305 } ); 1306 1307 // Evaluate parameters 1308 $.each( rules, function( rule, parameter ) { 1309 rules[ rule ] = $.isFunction( parameter ) && rule !== "normalizer" ? parameter( element ) : parameter; 1310 } ); 1311 1312 // Clean number parameters 1313 $.each( [ "minlength", "maxlength" ], function() { 1314 if ( rules[ this ] ) { 1315 rules[ this ] = Number( rules[ this ] ); 1316 } 1317 } ); 1318 $.each( [ "rangelength", "range" ], function() { 1319 var parts; 1320 if ( rules[ this ] ) { 1321 if ( $.isArray( rules[ this ] ) ) { 1322 rules[ this ] = [ Number( rules[ this ][ 0 ] ), Number( rules[ this ][ 1 ] ) ]; 1323 } else if ( typeof rules[ this ] === "string" ) { 1324 parts = rules[ this ].replace( /[\[\]]/g, "" ).split( /[\s,]+/ ); 1325 rules[ this ] = [ Number( parts[ 0 ] ), Number( parts[ 1 ] ) ]; 1326 } 1327 } 1328 } ); 1329 1330 if ( $.validator.autoCreateRanges ) { 1331 1332 // Auto-create ranges 1333 if ( rules.min != null && rules.max != null ) { 1334 rules.range = [ rules.min, rules.max ]; 1335 delete rules.min; 1336 delete rules.max; 1337 } 1338 if ( rules.minlength != null && rules.maxlength != null ) { 1339 rules.rangelength = [ rules.minlength, rules.maxlength ]; 1340 delete rules.minlength; 1341 delete rules.maxlength; 1342 } 1343 } 1344 1345 return rules; 1346 }, 1347 1348 // Converts a simple string to a {string: true} rule, e.g., "required" to {required:true} 1349 normalizeRule: function( data ) { 1350 if ( typeof data === "string" ) { 1351 var transformed = {}; 1352 $.each( data.split( /\s/ ), function() { 1353 transformed[ this ] = true; 1354 } ); 1355 data = transformed; 1356 } 1357 return data; 1358 }, 1359 1360 // https://jqueryvalidation.org/jQuery.validator.addMethod/ 1361 addMethod: function( name, method, message ) { 1362 $.validator.methods[ name ] = method; 1363 $.validator.messages[ name ] = message !== undefined ? message : $.validator.messages[ name ]; 1364 if ( method.length < 3 ) { 1365 $.validator.addClassRules( name, $.validator.normalizeRule( name ) ); 1366 } 1367 }, 1368 1369 // https://jqueryvalidation.org/jQuery.validator.methods/ 1370 methods: { 1371 1372 // https://jqueryvalidation.org/required-method/ 1373 required: function( value, element, param ) { 1374 1375 // Check if dependency is met 1376 if ( !this.depend( param, element ) ) { 1377 return "dependency-mismatch"; 1378 } 1379 if ( element.nodeName.toLowerCase() === "select" ) { 1380 1381 // Could be an array for select-multiple or a string, both are fine this way 1382 var val = $( element ).val(); 1383 return val && val.length > 0; 1384 } 1385 if ( this.checkable( element ) ) { 1386 return this.getLength( value, element ) > 0; 1387 } 1388 return value !== undefined && value !== null && value.length > 0; 1389 }, 1390 1391 // https://jqueryvalidation.org/email-method/ 1392 email: function( value, element ) { 1393 1394 // From https://html.spec.whatwg.org/multipage/forms.html#valid-e-mail-address 1395 // Retrieved 2014-01-14 1396 // If you have a problem with this implementation, report a bug against the above spec 1397 // Or use custom methods to implement your own email validation 1398 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 ); 1399 }, 1400 1401 // https://jqueryvalidation.org/url-method/ 1402 url: function( value, element ) { 1403 1404 // Copyright (c) 2010-2013 Diego Perini, MIT licensed 1405 // https://gist.github.com/dperini/729294 1406 // see also https://mathiasbynens.be/demo/url-regex 1407 // modified to allow protocol-relative URLs 1408 return this.optional( element ) || /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?: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-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test( value ); 1409 }, 1410 1411 // https://jqueryvalidation.org/date-method/ 1412 date: ( function() { 1413 var called = false; 1414 1415 return function( value, element ) { 1416 if ( !called ) { 1417 called = true; 1418 if ( this.settings.debug && window.console ) { 1419 console.warn( 1420 "The `date` method is deprecated and will be removed in version '2.0.0'.\n" + 1421 "Please don't use it, since it relies on the Date constructor, which\n" + 1422 "behaves very differently across browsers and locales. Use `dateISO`\n" + 1423 "instead or one of the locale specific methods in `localizations/`\n" + 1424 "and `additional-methods.js`." 1425 ); 1426 } 1427 } 1428 1429 return this.optional( element ) || !/Invalid|NaN/.test( new Date( value ).toString() ); 1430 }; 1431 }() ), 1432 1433 // https://jqueryvalidation.org/dateISO-method/ 1434 dateISO: function( value, element ) { 1435 return this.optional( element ) || /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test( value ); 1436 }, 1437 1438 // https://jqueryvalidation.org/number-method/ 1439 number: function( value, element ) { 1440 return this.optional( element ) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test( value ); 1441 }, 1442 1443 // https://jqueryvalidation.org/digits-method/ 1444 digits: function( value, element ) { 1445 return this.optional( element ) || /^\d+$/.test( value ); 1446 }, 1447 1448 // https://jqueryvalidation.org/minlength-method/ 1449 minlength: function( value, element, param ) { 1450 var length = $.isArray( value ) ? value.length : this.getLength( value, element ); 1451 return this.optional( element ) || length >= param; 1452 }, 1453 1454 // https://jqueryvalidation.org/maxlength-method/ 1455 maxlength: function( value, element, param ) { 1456 var length = $.isArray( value ) ? value.length : this.getLength( value, element ); 1457 return this.optional( element ) || length <= param; 1458 }, 1459 1460 // https://jqueryvalidation.org/rangelength-method/ 1461 rangelength: function( value, element, param ) { 1462 var length = $.isArray( value ) ? value.length : this.getLength( value, element ); 1463 return this.optional( element ) || ( length >= param[ 0 ] && length <= param[ 1 ] ); 1464 }, 1465 1466 // https://jqueryvalidation.org/min-method/ 1467 min: function( value, element, param ) { 1468 return this.optional( element ) || value >= param; 1469 }, 1470 1471 // https://jqueryvalidation.org/max-method/ 1472 max: function( value, element, param ) { 1473 return this.optional( element ) || value <= param; 1474 }, 1475 1476 // https://jqueryvalidation.org/range-method/ 1477 range: function( value, element, param ) { 1478 return this.optional( element ) || ( value >= param[ 0 ] && value <= param[ 1 ] ); 1479 }, 1480 1481 // https://jqueryvalidation.org/step-method/ 1482 step: function( value, element, param ) { 1483 var type = $( element ).attr( "type" ), 1484 errorMessage = "Step attribute on input type " + type + " is not supported.", 1485 supportedTypes = [ "text", "number", "range" ], 1486 re = new RegExp( "\\b" + type + "\\b" ), 1487 notSupported = type && !re.test( supportedTypes.join() ), 1488 decimalPlaces = function( num ) { 1489 var match = ( "" + num ).match( /(?:\.(\d+))?$/ ); 1490 if ( !match ) { 1491 return 0; 1492 } 1493 1494 // Number of digits right of decimal point. 1495 return match[ 1 ] ? match[ 1 ].length : 0; 1496 }, 1497 toInt = function( num ) { 1498 return Math.round( num * Math.pow( 10, decimals ) ); 1499 }, 1500 valid = true, 1501 decimals; 1502 1503 // Works only for text, number and range input types 1504 // TODO find a way to support input types date, datetime, datetime-local, month, time and week 1505 if ( notSupported ) { 1506 throw new Error( errorMessage ); 1507 } 1508 1509 decimals = decimalPlaces( param ); 1510 1511 // Value can't have too many decimals 1512 if ( decimalPlaces( value ) > decimals || toInt( value ) % toInt( param ) !== 0 ) { 1513 valid = false; 1514 } 1515 1516 return this.optional( element ) || valid; 1517 }, 1518 1519 // https://jqueryvalidation.org/equalTo-method/ 1520 equalTo: function( value, element, param ) { 1521 1522 // Bind to the blur event of the target in order to revalidate whenever the target field is updated 1523 var target = $( param ); 1524 if ( this.settings.onfocusout && target.not( ".validate-equalTo-blur" ).length ) { 1525 target.addClass( "validate-equalTo-blur" ).on( "blur.validate-equalTo", function() { 1526 $( element ).valid(); 1527 } ); 1528 } 1529 return value === target.val(); 1530 }, 1531 1532 // https://jqueryvalidation.org/remote-method/ 1533 remote: function( value, element, param, method ) { 1534 if ( this.optional( element ) ) { 1535 return "dependency-mismatch"; 1536 } 1537 1538 method = typeof method === "string" && method || "remote"; 1539 1540 var previous = this.previousValue( element, method ), 1541 validator, data, optionDataString; 1542 1543 if ( !this.settings.messages[ element.name ] ) { 1544 this.settings.messages[ element.name ] = {}; 1545 } 1546 previous.originalMessage = previous.originalMessage || this.settings.messages[ element.name ][ method ]; 1547 this.settings.messages[ element.name ][ method ] = previous.message; 1548 1549 param = typeof param === "string" && { url: param } || param; 1550 optionDataString = $.param( $.extend( { data: value }, param.data ) ); 1551 if ( previous.old === optionDataString ) { 1552 return previous.valid; 1553 } 1554 1555 previous.old = optionDataString; 1556 validator = this; 1557 this.startRequest( element ); 1558 data = {}; 1559 data[ element.name ] = value; 1560 $.ajax( $.extend( true, { 1561 mode: "abort", 1562 port: "validate" + element.name, 1563 dataType: "json", 1564 data: data, 1565 context: validator.currentForm, 1566 success: function( response ) { 1567 var valid = response === true || response === "true", 1568 errors, message, submitted; 1569 1570 validator.settings.messages[ element.name ][ method ] = previous.originalMessage; 1571 if ( valid ) { 1572 submitted = validator.formSubmitted; 1573 validator.resetInternals(); 1574 validator.toHide = validator.errorsFor( element ); 1575 validator.formSubmitted = submitted; 1576 validator.successList.push( element ); 1577 validator.invalid[ element.name ] = false; 1578 validator.showErrors(); 1579 } else { 1580 errors = {}; 1581 message = response || validator.defaultMessage( element, { method: method, parameters: value } ); 1582 errors[ element.name ] = previous.message = message; 1583 validator.invalid[ element.name ] = true; 1584 validator.showErrors( errors ); 1585 } 1586 previous.valid = valid; 1587 validator.stopRequest( element, valid ); 1588 } 1589 }, param ) ); 1590 return "pending"; 1591 } 1592 } 1593 1594} );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.