Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 8c44ec2

Browse files
Code cleanup and test fixes
Cleanup some code from PR #149 and fix the broken unit tests and hopefully make it so that failing unit tests will fail the travis build again
1 parent 85806bd commit 8c44ec2

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Inside of `ui-options`, you can customize these five properties:
6767
* `eventsToHandle` - default: `['input', 'keyup', 'click', 'focus']`
6868
* `addDefaultPlaceholder` - default: `true`
6969
* `escChar` - default: `'\\'`
70-
* `unsafe` - default: `false`
70+
* `allowInvalidValue` - default: `false`
7171

7272
When customizing `eventsToHandle`, `clearOnBlur`, or `addDefaultPlaceholder`, the value you supply will replace the default. To customize `eventsToHandle`, be sure to replace the entire array.
7373

@@ -77,7 +77,7 @@ When setting `clearOnBlurPlaceholder` to `true`, it will show the placeholder te
7777

7878
If the `escChar` (\\ by default) is encountered in a mask, the next character will be treated as a literal and not a mask definition key. To disable the `escChar` feature completely, set `escChar` to `null`.
7979

80-
When `unsafe` set to true, apply value to `$modelValue` even if it isn't valid. By default, if you write invalid value, model stay `undefined`.
80+
When `allowInvalidValue` is set to true, apply value to `$modelValue` even if it isn't valid. By default, if you write an invalid value, the model will stay `undefined`.
8181

8282
#### Global customization
8383
In addition to customizing behaviors for a specific element, you can also customize the behaviors globally. To do this, simply use the `uiMaskConfig` provider in your app configuration. Example:

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ gulp.task('karma-sauce', ['build', 'start-sauce-connect'], function(callback) {
121121
karma: Server,
122122
customLaunchers: customLaunchers
123123
}, function(code) {
124-
callback();
124+
callback(code);
125125
});
126126
});
127127

src/mask.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ angular.module('ui.mask', [])
1212
clearOnBlurPlaceholder: false,
1313
escChar: '\\',
1414
eventsToHandle: ['input', 'keyup', 'click', 'focus'],
15-
addDefaultPlaceholder: true
15+
addDefaultPlaceholder: true,
16+
allowInvalidValue: false
1617
})
1718
.provider('uiMask.Config', function() {
1819
var options = {};
@@ -58,7 +59,7 @@ angular.module('ui.mask', [])
5859
require: 'ngModel',
5960
restrict: 'A',
6061
compile: function uiMaskCompilingFunction() {
61-
var options = maskConfig;
62+
var options = angular.copy(maskConfig);
6263

6364
return function uiMaskLinkingFunction(scope, iElement, iAttrs, controller) {
6465
var maskProcessed = false, eventsBound = false,
@@ -161,12 +162,8 @@ angular.module('ui.mask', [])
161162
controller.$viewValue = value.length ? maskValue(value) : '';
162163
controller.$setValidity('mask', isValid);
163164

164-
if (modelViewValue) value = controller.$viewValue;
165-
if (!value.length) return undefined;
166165
if (isValid || linkOptions.allowInvalidValue) {
167-
return value;
168-
} else {
169-
return undefined;
166+
return modelViewValue ? controller.$viewValue : value;
170167
}
171168
}
172169

0 commit comments

Comments
 (0)