|
24 | 24 |
|
25 | 25 | if (typeof (ko) === undefined) { throw 'Knockout is required, please ensure it is loaded before loading this validation plug-in'; } |
26 | 26 |
|
27 | | - if (typeof define === "function" && define["amd"]) { |
28 | | - exports = ko.validation = {}; |
29 | | - } |
| 27 | + // create our namespace object |
| 28 | + var validation = exports; |
| 29 | + ko.validation = validation; |
30 | 30 |
|
31 | 31 | var defaults = { |
32 | 32 | registerExtenders: true, |
|
146 | 146 | //#endregion |
147 | 147 |
|
148 | 148 | //#region Public API |
149 | | - var validation = (function () { |
| 149 | + var api = (function () { |
150 | 150 |
|
151 | 151 | var isInitialized = 0; |
152 | 152 |
|
|
453 | 453 | contexts = null; |
454 | 454 | } |
455 | 455 | }; |
456 | | - } ()); |
| 456 | + }()); |
| 457 | + |
| 458 | + // expose api publicly |
| 459 | + ko.utils.extend(validation, api); |
457 | 460 | //#endregion |
458 | 461 |
|
459 | 462 | //#region Core Validation Rules |
|
532 | 535 |
|
533 | 536 | validation.rules['pattern'] = { |
534 | 537 | validator: function (val, regex) { |
535 | | - return utils.isEmptyVal(val) || val.match(regex) != null; |
| 538 | + return utils.isEmptyVal(val) || val.toString().match(regex) != null; |
536 | 539 | }, |
537 | 540 | message: 'Please check this value.' |
538 | 541 | }; |
|
739 | 742 |
|
740 | 743 | //toggle visibility on validation messages when validation hasn't been evaluated, or when the object isValid |
741 | 744 | var visiblityAccessor = function () { |
742 | | - return isModified ? !isValid : false; |
| 745 | + return (!config.messagesOnModified || isModified) ? !isValid : false; |
743 | 746 | }; |
744 | 747 |
|
745 | 748 | ko.bindingHandlers.text.update(element, errorMsgAccessor); |
|
1072 | 1075 | }; |
1073 | 1076 |
|
1074 | 1077 | //#endregion |
1075 | | - |
1076 | | - /// apply our public api to the public object |
1077 | | - ko.utils.extend(exports, validation); |
1078 | | - |
1079 | 1078 | })); |
0 commit comments