|
31 | 31 |
|
32 | 32 | // Check if a validator for this form was already created
|
33 | 33 | var validator = $.data( this[ 0 ], "validator" );
|
| 34 | + |
34 | 35 | if ( validator ) {
|
35 | 36 | return validator;
|
36 | 37 | }
|
|
235 | 236 | // https://jqueryvalidation.org/filled-selector/
|
236 | 237 | filled: function( a ) {
|
237 | 238 | var val = $( a ).val();
|
| 239 | + |
238 | 240 | return val !== null && !!trim( "" + val );
|
239 | 241 | },
|
240 | 242 |
|
|
256 | 258 | if ( arguments.length === 1 ) {
|
257 | 259 | return function() {
|
258 | 260 | var args = $.makeArray( arguments );
|
| 261 | + |
259 | 262 | args.unshift( source );
|
260 | 263 | return $.validator.format.apply( this, args );
|
261 | 264 | };
|
|
406 | 409 | var currentForm = this.currentForm,
|
407 | 410 | groups = this.groups = {},
|
408 | 411 | rules;
|
| 412 | + |
409 | 413 | $.each( this.settings.groups, function( key, value ) {
|
410 | 414 | if ( typeof value === "string" ) {
|
411 | 415 | value = value.split( /\s/ );
|
|
420 | 424 | } );
|
421 | 425 |
|
422 | 426 | function delegate( event ) {
|
423 |
| - var isContentEditable = typeof $( this ).attr( "contenteditable" ) !== "undefined" && $( this ).attr( "contenteditable" ) !== "false"; |
| 427 | + var isContentEditable = typeof $( this ).attr( "contenteditable" ) !== "undefined" |
| 428 | + && $( this ).attr( "contenteditable" ) !== "false"; |
424 | 429 |
|
425 | 430 | // Set form expando on contenteditable
|
426 | 431 | if ( !this.form && isContentEditable ) {
|
|
437 | 442 | var validator = $.data( this.form, "validator" ),
|
438 | 443 | eventType = "on" + event.type.replace( /^validate/, "" ),
|
439 | 444 | settings = validator.settings;
|
| 445 | + |
440 | 446 | if ( settings[ eventType ] && !$( this ).is( settings.ignore ) ) {
|
441 | 447 | settings[ eventType ].call( validator, this, event );
|
442 | 448 | }
|
|
477 | 483 | if ($(this.currentForm).find('.bundle').length > 0
|
478 | 484 | && $(this.currentForm).find('input[type="checkbox"]').length > 0) {
|
479 | 485 | return this.checkBundleForm();
|
480 |
| - } else { |
481 |
| - return this.checkDefaultForm(); |
482 | 486 | }
|
| 487 | + return this.checkDefaultForm(); |
483 | 488 | },
|
484 | 489 |
|
485 | 490 | checkBundleForm: function() {
|
486 |
| - var group, optionNumber, elements, optionMap, el, option; |
| 491 | + var optionNumber, elements, optionMap, el, option; |
| 492 | + |
487 | 493 | this.prepareForm();
|
488 | 494 | elements = this.elements();
|
489 | 495 | optionMap = {};
|
|
502 | 508 | }
|
503 | 509 | return this.valid();
|
504 | 510 | },
|
| 511 | + |
505 | 512 | processOptionGroup: function(group) {
|
506 | 513 | if (group.length > 0) {
|
507 | 514 | this.check(group[0]);
|
508 | 515 | }
|
509 | 516 | },
|
| 517 | + |
510 | 518 | checkDefaultForm: function() {
|
511 | 519 | this.prepareForm();
|
512 | 520 | for (var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++) {
|
|
632 | 640 | /* jshint unused: false */
|
633 | 641 | var count = 0,
|
634 | 642 | i;
|
| 643 | + |
635 | 644 | for ( i in obj ) {
|
636 | 645 |
|
637 | 646 | // This check allows counting elements with empty error
|
|
678 | 687 |
|
679 | 688 | findLastActive: function() {
|
680 | 689 | var lastActive = this.lastActive;
|
| 690 | + |
681 | 691 | return lastActive && $.grep( this.errorList, function( n ) {
|
682 | 692 | return n.element.name === lastActive.name;
|
683 | 693 | } ).length === 1 && lastActive;
|
|
694 | 704 | .not( this.settings.ignore )
|
695 | 705 | .filter( function() {
|
696 | 706 | var name = this.name || $( this ).attr( "name" ); // For contenteditable
|
697 |
| - var isContentEditable = typeof $( this ).attr( "contenteditable" ) !== "undefined" && $( this ).attr( "contenteditable" ) !== "false"; |
| 707 | + |
| 708 | + var isContentEditable = typeof $( this ).attr( "contenteditable" ) !== "undefined" |
| 709 | + && $( this ).attr( "contenteditable" ) !== "false"; |
698 | 710 |
|
699 | 711 | if ( !name && validator.settings.debug && window.console ) {
|
700 | 712 | console.error( "%o has no name assigned", this );
|
|
727 | 739 |
|
728 | 740 | errors: function() {
|
729 | 741 | var errorClass = this.settings.errorClass.split( " " ).join( "." );
|
| 742 | + |
730 | 743 | return $( this.settings.errorElement + "." + errorClass, this.errorContext );
|
731 | 744 | },
|
732 | 745 |
|
|
883 | 896 | // Return the custom message for the given element name and validation method
|
884 | 897 | customMessage: function( name, method ) {
|
885 | 898 | var m = this.settings.messages[ name ];
|
| 899 | + |
886 | 900 | return m && ( m.constructor === String ? m : m[ method ] );
|
887 | 901 | },
|
888 | 902 |
|
|
951 | 965 |
|
952 | 966 | defaultShowErrors: function() {
|
953 | 967 | var i, elements, error;
|
| 968 | + |
954 | 969 | for ( i = 0; this.errorList[ i ]; i++ ) {
|
955 | 970 | error = this.errorList[ i ];
|
956 | 971 | if ( this.settings.highlight ) {
|
|
1148 | 1163 |
|
1149 | 1164 | optional: function( element ) {
|
1150 | 1165 | var val = this.elementValue( element );
|
| 1166 | + |
1151 | 1167 | return !$.validator.methods.required.call( this, val, element ) && "dependency-mismatch";
|
1152 | 1168 | },
|
1153 | 1169 |
|
|
1319 | 1335 | }
|
1320 | 1336 |
|
1321 | 1337 | var meta = $.data(element.form, 'validator').settings.meta;
|
| 1338 | + |
1322 | 1339 | return meta ?
|
1323 | 1340 | $(element).metadata()[meta] :
|
1324 | 1341 | $(element).metadata();
|
|
1364 | 1381 | }
|
1365 | 1382 | if ( val.param || val.depends ) {
|
1366 | 1383 | var keepRule = true;
|
| 1384 | + |
1367 | 1385 | switch ( typeof val.depends ) {
|
1368 | 1386 | case "string":
|
1369 | 1387 | keepRule = !!$( val.depends, element.form ).length;
|
|
1375 | 1393 | if ( keepRule ) {
|
1376 | 1394 | rules[ prop ] = val.param !== undefined ? val.param : true;
|
1377 | 1395 | } else {
|
1378 |
| - $.data( element.form, "validator" ).resetElements( $( element ) ); |
| 1396 | + $.data(element.form, "validator").resetElements($(element)); |
1379 | 1397 | delete rules[ prop ];
|
1380 | 1398 | }
|
1381 | 1399 | }
|
|
1394 | 1412 | } );
|
1395 | 1413 | $.each( [ "rangelength", "range" ], function() {
|
1396 | 1414 | var parts;
|
| 1415 | + |
1397 | 1416 | if ( rules[ this ] ) {
|
1398 | 1417 | if ( Array.isArray( rules[ this ] ) ) {
|
1399 | 1418 | rules[ this ] = [ Number( rules[ this ][ 0 ] ), Number( rules[ this ][ 1 ] ) ];
|
|
1426 | 1445 | normalizeRule: function( data ) {
|
1427 | 1446 | if ( typeof data === "string" ) {
|
1428 | 1447 | var transformed = {};
|
| 1448 | + |
1429 | 1449 | $.each( data.split( /\s/ ), function() {
|
1430 | 1450 | transformed[ this ] = true;
|
1431 | 1451 | } );
|
|
1457 | 1477 |
|
1458 | 1478 | // Could be an array for select-multiple or a string, both are fine this way
|
1459 | 1479 | var val = $( element ).val();
|
| 1480 | + |
1460 | 1481 | return val && val.length > 0;
|
1461 | 1482 | }
|
1462 | 1483 | if ( this.checkable( element ) ) {
|
|
1578 | 1599 | toInt = function( num ) {
|
1579 | 1600 | return Math.round( num * Math.pow( 10, decimals ) );
|
1580 | 1601 | },
|
1581 |
| - valid = true, |
1582 |
| - decimals; |
| 1602 | + valid = true; |
1583 | 1603 |
|
1584 | 1604 | // Works only for text, number and range input types
|
1585 | 1605 | // TODO find a way to support input types date, datetime, datetime-local, month, time and week
|
|
1602 | 1622 |
|
1603 | 1623 | // Bind to the blur event of the target in order to revalidate whenever the target field is updated
|
1604 | 1624 | var target = $( param );
|
| 1625 | + |
1605 | 1626 | if ( this.settings.onfocusout && target.not( ".validate-equalTo-blur" ).length ) {
|
1606 | 1627 | target.addClass( "validate-equalTo-blur" ).on( "blur.validate-equalTo", function() {
|
1607 | 1628 | $( element ).valid();
|
|
0 commit comments