|
404 | 404 | this.reset();
|
405 | 405 |
|
406 | 406 | var currentForm = this.currentForm,
|
407 |
| - groups = ( this.groups = {} ), |
| 407 | + groups = this.groups = {}, |
408 | 408 | rules;
|
409 | 409 | $.each( this.settings.groups, function( key, value ) {
|
410 | 410 | if ( typeof value === "string" ) {
|
|
444 | 444 |
|
445 | 445 | $( this.currentForm )
|
446 | 446 | .on( "focusin.validate focusout.validate keyup.validate",
|
447 |
| - ":text, [type='password'], [type='file'], select, textarea, [type='number'], [type='search'], " + |
448 |
| - "[type='tel'], [type='url'], [type='email'], [type='datetime'], [type='date'], [type='month'], " + |
449 |
| - "[type='week'], [type='time'], [type='datetime-local'], [type='range'], [type='color'], " + |
| 447 | + ":text, [type='password'], [type='file'], " + |
| 448 | + "select, textarea, [type='number'], [type='search'], " + |
| 449 | + "[type='tel'], [type='url'], [type='email'], " + |
| 450 | + "[type='datetime'], [type='date'], [type='month'], " + |
| 451 | + "[type='week'], [type='time'], [type='datetime-local'], " + |
| 452 | + "[type='range'], [type='color'], " + |
450 | 453 | "[type='radio'], [type='checkbox'], [contenteditable], [type='button']", delegate )
|
451 | 454 |
|
452 | 455 | // Support: Chrome, oldIE
|
|
471 | 474 | },
|
472 | 475 |
|
473 | 476 | checkForm: function() {
|
474 |
| - if ($(this.currentForm).find('.bundle').length > 0) { |
475 |
| - this.prepareForm(); |
476 |
| - var elements = this.elements(); |
477 |
| - var optionMap = {}; |
478 |
| - for (var i = 0; i < elements.length; i++) { |
479 |
| - var el = elements[i]; |
480 |
| - var optionNumber = el.id.split('-')[2]; |
481 |
| - if (!optionMap[optionNumber]) { |
482 |
| - optionMap[optionNumber] = []; |
483 |
| - } |
484 |
| - optionMap[optionNumber].push(el); |
485 |
| - } |
486 |
| - for (var option in optionMap) { |
487 |
| - if (optionMap.hasOwnProperty(option)) { |
488 |
| - var group = optionMap[option]; |
489 |
| - if (group.length > 0) { |
490 |
| - this.check(group[0]); |
491 |
| - } |
492 |
| - } |
493 |
| - } |
494 |
| - return this.valid(); |
| 477 | + if ($(this.currentForm).find('.bundle').length > 0 |
| 478 | + && $(this.currentForm).find('input[type="checkbox"]').length > 0) { |
| 479 | + return this.checkBundleForm(); |
495 | 480 | } else {
|
496 |
| - this.prepareForm(); |
497 |
| - for ( var i = 0, elements = ( this.currentElements = this.elements() ); elements[ i ]; i++ ) { |
498 |
| - this.check( elements[ i ] ); |
| 481 | + return this.checkDefaultForm(); |
| 482 | + } |
| 483 | + }, |
| 484 | + |
| 485 | + checkBundleForm: function() { |
| 486 | + var group, optionNumber, elements, optionMap, el, option; |
| 487 | + this.prepareForm(); |
| 488 | + elements = this.elements(); |
| 489 | + optionMap = {}; |
| 490 | + for (var i = 0; i < elements.length; i++) { |
| 491 | + el = elements[i]; |
| 492 | + optionNumber = el.id.split('-')[2]; |
| 493 | + if (!optionMap[optionNumber]) { |
| 494 | + optionMap[optionNumber] = []; |
| 495 | + } |
| 496 | + optionMap[optionNumber].push(el); |
| 497 | + } |
| 498 | + for (option in optionMap) { |
| 499 | + if (optionMap.hasOwnProperty(option)) { |
| 500 | + this.processOptionGroup(optionMap[option]); |
499 | 501 | }
|
500 |
| - return this.valid(); |
501 | 502 | }
|
| 503 | + return this.valid(); |
| 504 | + }, |
| 505 | + processOptionGroup: function(group) { |
| 506 | + if (group.length > 0) { |
| 507 | + this.check(group[0]); |
| 508 | + } |
| 509 | + }, |
| 510 | + checkDefaultForm: function() { |
| 511 | + this.prepareForm(); |
| 512 | + for (var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++) { |
| 513 | + this.check(elements[i]); |
| 514 | + } |
| 515 | + return this.valid(); |
502 | 516 | },
|
503 | 517 |
|
504 | 518 | // https://jqueryvalidation.org/Validator.element/
|
|
1309 | 1323 | $(element).metadata()[meta] :
|
1310 | 1324 | $(element).metadata();
|
1311 | 1325 | },
|
1312 |
| - |
1313 | 1326 | dataRules: function( element ) {
|
1314 | 1327 | var rules = {},
|
1315 | 1328 | $element = $( element ),
|
|
1512 | 1525 | // https://jqueryvalidation.org/minlength-method/
|
1513 | 1526 | minlength: function( value, element, param ) {
|
1514 | 1527 | var length = Array.isArray( value ) ? value.length : this.getLength( value, element );
|
| 1528 | + |
1515 | 1529 | return this.optional( element ) || length >= param;
|
1516 | 1530 | },
|
1517 | 1531 |
|
1518 | 1532 | // https://jqueryvalidation.org/maxlength-method/
|
1519 | 1533 | maxlength: function( value, element, param ) {
|
1520 | 1534 | var length = Array.isArray( value ) ? value.length : this.getLength( value, element );
|
| 1535 | + |
1521 | 1536 | return this.optional( element ) || length <= param;
|
1522 | 1537 | },
|
1523 | 1538 |
|
1524 | 1539 | // https://jqueryvalidation.org/rangelength-method/
|
1525 | 1540 | rangelength: function( value, element, param ) {
|
1526 | 1541 | var length = Array.isArray( value ) ? value.length : this.getLength( value, element );
|
| 1542 | + |
1527 | 1543 | return this.optional( element ) || ( length >= param[ 0 ] && length <= param[ 1 ] );
|
1528 | 1544 | },
|
1529 | 1545 |
|
|
1558 | 1574 | // Number of digits right of decimal point.
|
1559 | 1575 | return match[ 1 ] ? match[ 1 ].length : 0;
|
1560 | 1576 | },
|
| 1577 | + decimals = 0, |
1561 | 1578 | toInt = function( num ) {
|
1562 | 1579 | return Math.round( num * Math.pow( 10, decimals ) );
|
1563 | 1580 | },
|
|
1628 | 1645 | data: data,
|
1629 | 1646 | context: validator.currentForm,
|
1630 | 1647 | success: function( response ) {
|
1631 |
| - var valid = response === true || response === "true", |
| 1648 | + var valid = response === true || response === 'true', |
1632 | 1649 | errors, message, submitted;
|
1633 | 1650 |
|
1634 | 1651 | validator.settings.messages[ element.name ][ method ] = previous.originalMessage;
|
|
0 commit comments