|
2 | 2 | * jQuery Form Validation |
3 | 3 | * |
4 | 4 | * @author Tom Bertrand |
5 | | - * @version 1.3.0 (2014-07-24) |
| 5 | + * @version 1.3.0 (2014-07-25) |
6 | 6 | * |
7 | 7 | * @copyright |
8 | 8 | * Copyright (C) 2014 Tom Bertrand. |
|
457 | 457 | */ |
458 | 458 | function validateForm () { |
459 | 459 |
|
| 460 | + var isValid = true; |
| 461 | + |
460 | 462 | $.each( |
461 | 463 | $(node).find('[' + _data.validation + '],[' + _data.regex + ']'), |
462 | 464 | function (index, input) { |
|
465 | 467 | return false; |
466 | 468 | } |
467 | 469 |
|
468 | | - validateInput(input); |
| 470 | + if (!validateInput(input)) { |
| 471 | + isValid = false; |
| 472 | + } |
469 | 473 |
|
470 | 474 | } |
471 | 475 | ); |
472 | 476 |
|
473 | | - return $.isEmptyObject(errors); |
| 477 | + return isValid; |
474 | 478 |
|
475 | 479 | } |
476 | 480 |
|
|
515 | 519 | } |
516 | 520 |
|
517 | 521 | // Validates the "data-validation" |
518 | | - if (!$.isEmptyObject(validationArray)) { |
| 522 | + if (validationArray instanceof Array && validationArray.length > 0) { |
519 | 523 |
|
520 | 524 | // "OPTIONAL" input will not be validated if it's empty |
521 | 525 | if (value === '' && $.inArray('OPTIONAL', validationArray) !== -1) { |
|
590 | 594 | 'message': 'WARNING - Invalid [data-validation-regex] on input ' + inputName |
591 | 595 | }); |
592 | 596 |
|
| 597 | + // Do not block validation if a regexp is bad, only skip it |
593 | 598 | return true; |
594 | 599 |
|
595 | 600 | } |
|
608 | 613 |
|
609 | 614 | } |
610 | 615 |
|
611 | | - return $.isEmptyObject(errors[inputName]); |
| 616 | + return !errors[inputName] || errors[inputName] instanceof Array && errors[inputName].length === 0; |
612 | 617 |
|
613 | 618 | } |
614 | 619 |
|
|
835 | 840 | errorContainer = $(node); |
836 | 841 | } |
837 | 842 |
|
| 843 | + // Prevent double error list if the previous one has not been cleared. |
| 844 | + if (options.submit.settings.display === 'inline' && errorContainer.find('[' + _data.errorList + ']')[0]) { |
| 845 | + return false; |
| 846 | + } |
| 847 | + |
838 | 848 | if (options.submit.settings.display === "inline" || |
839 | 849 | (options.submit.settings.display === "block" && !errorContainer.find('[' + _data.errorList + ']')[0]) |
840 | 850 | ) { |
|
870 | 880 | input.unbind(event).on(event, function (a,b,c,d,e) { |
871 | 881 |
|
872 | 882 | return function () { |
873 | | - |
874 | 883 | if (e) { |
875 | | - |
876 | 884 | if ($(c).hasClass(options.submit.settings.errorClass)) { |
877 | 885 | resetOneError(a,b,c,d,e); |
878 | 886 | } |
879 | | - |
880 | 887 | } else if ($(b).hasClass(options.submit.settings.errorClass)) { |
881 | 888 | resetOneError(a,b,c,d); |
882 | 889 | } |
|
1466 | 1473 | return false; |
1467 | 1474 | } |
1468 | 1475 |
|
1469 | | - if (typeof error !== "object" || $.isEmptyObject(error) || Object.prototype.toString.call(error) !== "[object Object]") { |
| 1476 | + if (typeof error !== "object" || Object.prototype.toString.call(error) !== "[object Object]") { |
1470 | 1477 | window.debug('$.addError - Invalid error object.'); |
1471 | 1478 | return false; |
1472 | 1479 | } |
|
1518 | 1525 | * Note: The same form jQuery selector MUST be used to recuperate the Validation configuration. |
1519 | 1526 | * |
1520 | 1527 | * @example |
1521 | | - * $('#form-signup_v3').removeError([ |
| 1528 | + * $('#form-signin_v2').removeError([ |
1522 | 1529 | * 'signin_v2[username]', |
1523 | 1530 | * 'signin_v2[password]' |
1524 | 1531 | * ]) |
|
1540 | 1547 | return false; |
1541 | 1548 | } |
1542 | 1549 |
|
1543 | | - if (typeof inputName === "object" && ($.isEmptyObject(inputName) || Object.prototype.toString.call(inputName) !== "[object Array]")) { |
| 1550 | + if (typeof inputName === "object" && Object.prototype.toString.call(inputName) !== "[object Array]") { |
1544 | 1551 | window.debug('$.removeError - Invalid inputName array.'); |
1545 | 1552 | return false; |
1546 | 1553 | } |
|
1579 | 1586 |
|
1580 | 1587 | window.Debug = { |
1581 | 1588 |
|
1582 | | - table: [], |
| 1589 | + table: {}, |
1583 | 1590 | log: function (debugObject) { |
1584 | 1591 |
|
1585 | 1592 | if (!debugObject.message || typeof debugObject.message !== "string") { |
|
1621 | 1628 | console.log('Debug is not available on your current browser, try the most recent version of Chrome or Firefox.'); |
1622 | 1629 | } |
1623 | 1630 |
|
1624 | | - this.table = []; |
| 1631 | + this.table = {}; |
1625 | 1632 |
|
1626 | 1633 | } |
1627 | 1634 |
|
|
0 commit comments