|
2 | 2 | * jQuery Form Validation |
3 | 3 | * |
4 | 4 | * @author Tom Bertrand |
5 | | - * @version 1.3.0 (2014-07-25) |
| 5 | + * @version 1.3.1 (2014-07-31) |
6 | 6 | * |
7 | 7 | * @copyright |
8 | 8 | * Copyright (C) 2014 Tom Bertrand. |
|
1328 | 1328 | if (typeof node === "function") { |
1329 | 1329 |
|
1330 | 1330 | if (!options.submit.settings.form) { |
1331 | | - window.debug('$.validate - Undefined property "options.submit.settings.form" - Validation dropped.'); |
| 1331 | + |
| 1332 | + window.Debug.log({ |
| 1333 | + 'node': node, |
| 1334 | + 'function': '$.validate()', |
| 1335 | + 'arguments': '', |
| 1336 | + 'message': 'Undefined property "options.submit.settings.form - Validation dropped' |
| 1337 | + }); |
| 1338 | + |
| 1339 | + window.Debug.print(); |
1332 | 1340 | return; |
1333 | 1341 | } |
1334 | 1342 |
|
1335 | 1343 | node = $(options.submit.settings.form); |
1336 | 1344 |
|
1337 | 1345 | if (!node[0]) { |
1338 | | - window.debug('$.validate - Unable to find jQuery form element "options.submit.settings.form" - ' + options.submit.settings.form + ' - Validation dropped.'); |
| 1346 | + window.Debug.log({ |
| 1347 | + 'node': node, |
| 1348 | + 'function': '$.validate()', |
| 1349 | + 'arguments': JSON.stringify(options.submit.settings.form), |
| 1350 | + 'message': 'Unable to find jQuery form element - Validation dropped' |
| 1351 | + }); |
| 1352 | + |
| 1353 | + window.Debug.print(); |
1339 | 1354 | return; |
1340 | 1355 | } |
1341 | 1356 |
|
1342 | 1357 | } else if (typeof node[0] === 'undefined') { |
1343 | 1358 |
|
1344 | | - window.debug('$("' + node['selector'] + '").validate() - Unable to find jQuery element - Validation dropped.'); |
1345 | | - return; |
| 1359 | + window.Debug.log({ |
| 1360 | + 'node': node, |
| 1361 | + 'function': '$.validate()', |
| 1362 | + 'arguments': '$("' + node['selector'] + '").validate()', |
| 1363 | + 'message': 'Unable to find jQuery form element - Validation dropped' |
| 1364 | + }); |
1346 | 1365 |
|
| 1366 | + window.Debug.print(); |
| 1367 | + return; |
1347 | 1368 | } |
1348 | 1369 |
|
1349 | 1370 | return node.each(function () { |
|
1469 | 1490 | addError: function (node, error) { |
1470 | 1491 |
|
1471 | 1492 | if (!window.Validation.form[node.selector]) { |
1472 | | - window.debug('$.addError - Invalid node selector - Make sure you are using the same one you initialize the Validation with.'); |
| 1493 | + |
| 1494 | + window.Debug.log({ |
| 1495 | + 'node': node, |
| 1496 | + 'function': '$.addError()', |
| 1497 | + 'arguments': 'window.Validation.form[' + JSON.stringify(node.selector) + ']', |
| 1498 | + 'message': 'ERROR - Invalid node selector' |
| 1499 | + }); |
| 1500 | + |
| 1501 | + window.Debug.print(); |
1473 | 1502 | return false; |
1474 | 1503 | } |
1475 | 1504 |
|
1476 | 1505 | if (typeof error !== "object" || Object.prototype.toString.call(error) !== "[object Object]") { |
1477 | | - window.debug('$.addError - Invalid error object.'); |
| 1506 | + |
| 1507 | + window.Debug.log({ |
| 1508 | + 'node': node, |
| 1509 | + 'function': '$.addError()', |
| 1510 | + 'arguments': 'window.Validation.form[' + JSON.stringify(node.selector) + ']', |
| 1511 | + 'message': 'ERROR - Invalid argument, must be type object' |
| 1512 | + }); |
| 1513 | + |
| 1514 | + window.Debug.print(); |
1478 | 1515 | return false; |
1479 | 1516 | } |
1480 | 1517 |
|
|
1492 | 1529 |
|
1493 | 1530 | input = $(node.selector).find('[name="'+ inputName + '"]'); |
1494 | 1531 | if (!input[0]) { |
1495 | | - window.debug('$.addError - Unable to find [name="' + inputName + '"] inside form: ' + node.selector + '.'); |
| 1532 | + |
| 1533 | + window.Debug.log({ |
| 1534 | + 'node': node, |
| 1535 | + 'function': '$.addError()', |
| 1536 | + 'arguments': JSON.stringify(inputName), |
| 1537 | + 'message': 'ERROR - Unable to find ' + '$(' + node.selector + ').find("[name="'+ inputName + '"]")' |
| 1538 | + }); |
| 1539 | + |
| 1540 | + window.Debug.print(); |
1496 | 1541 | continue; |
1497 | 1542 | } |
1498 | 1543 |
|
|
1506 | 1551 | for (var i = 0; i < error[inputName].length; i++) { |
1507 | 1552 |
|
1508 | 1553 | if (typeof error[inputName][i] !== "string") { |
1509 | | - window.debug('$.addError - Invalid error object property - Accepted format: {"inputName": "errorString"} or {"inputName": ["errorString", "errorString"]}.'); |
| 1554 | + |
| 1555 | + window.Debug.log({ |
| 1556 | + 'node': node, |
| 1557 | + 'function': '$.addError()', |
| 1558 | + 'arguments': JSON.stringify(error[inputName][i]), |
| 1559 | + 'message': 'ERROR - Invalid error object property - Accepted format: {"inputName": "errorString"} or {"inputName": ["errorString", "errorString"]}' |
| 1560 | + }); |
| 1561 | + |
| 1562 | + window.Debug.print(); |
1510 | 1563 | continue; |
1511 | 1564 | } |
1512 | 1565 |
|
|
1538 | 1591 | removeError: function (node, inputName) { |
1539 | 1592 |
|
1540 | 1593 | if (!window.Validation.form[node.selector]) { |
1541 | | - window.debug('$.removeError - Invalid node selector - Make sure you are using the same one you initialize the Validation with.'); |
| 1594 | + |
| 1595 | + window.Debug.log({ |
| 1596 | + 'node': node, |
| 1597 | + 'function': '$.removeError()', |
| 1598 | + 'arguments': 'window.Validation.form[' + JSON.stringify(node.selector) + ']', |
| 1599 | + 'message': 'ERROR - Invalid node selector' |
| 1600 | + }); |
| 1601 | + |
| 1602 | + window.Debug.print(); |
1542 | 1603 | return false; |
1543 | 1604 | } |
1544 | 1605 |
|
|
1548 | 1609 | } |
1549 | 1610 |
|
1550 | 1611 | if (typeof inputName === "object" && Object.prototype.toString.call(inputName) !== "[object Array]") { |
1551 | | - window.debug('$.removeError - Invalid inputName array.'); |
| 1612 | + |
| 1613 | + window.Debug.log({ |
| 1614 | + 'node': node, |
| 1615 | + 'function': '$.removeError()', |
| 1616 | + 'arguments': JSON.stringify(inputName), |
| 1617 | + 'message': 'ERROR - Invalid inputName, must be type String or Array' |
| 1618 | + }); |
| 1619 | + |
| 1620 | + window.Debug.print(); |
1552 | 1621 | return false; |
1553 | 1622 | } |
1554 | 1623 |
|
|
1561 | 1630 |
|
1562 | 1631 | input = $(node.selector).find('[name="'+ inputName[i] + '"]'); |
1563 | 1632 | if (!input[0]) { |
1564 | | - window.debug('$.removeError - Unable to find [name="' + inputName[i] + '"] inside form: ' + node.selector + '.'); |
| 1633 | + |
| 1634 | + window.Debug.log({ |
| 1635 | + 'node': node, |
| 1636 | + 'function': '$.removeError()', |
| 1637 | + 'arguments': JSON.stringify(inputName[i]), |
| 1638 | + 'message': 'ERROR - Unable to find ' + '$(' + node.selector + ').find("[name="'+ inputName[i] + '"]")' |
| 1639 | + }); |
| 1640 | + |
| 1641 | + window.Debug.print(); |
1565 | 1642 | continue; |
1566 | 1643 | } |
1567 | 1644 |
|
|
1573 | 1650 |
|
1574 | 1651 | }; |
1575 | 1652 |
|
1576 | | - /** |
1577 | | - * Creates a fail-safe debugging system inside the console |
1578 | | - */ |
1579 | | - window.debug = function () { |
1580 | | - if (this.console && this.console.debug) { |
1581 | | - this.console.debug('DEBUG: ' + Array.prototype.slice.call(arguments)); |
1582 | | - } else { |
1583 | | - window.log('DEBUG: ' + Array.prototype.slice.call(arguments)); |
1584 | | - } |
1585 | | - }; |
1586 | | - |
1587 | 1653 | window.Debug = { |
1588 | 1654 |
|
1589 | 1655 | table: {}, |
|
0 commit comments