Giter Site home page Giter Site logo

angular-ui / ui-mask Goto Github PK

View Code? Open in Web Editor NEW
390.0 25.0 258.0 6.13 MB

Mask on an input field so the user can only type pre-determined pattern

Home Page: https://htmlpreview.github.io/?https://github.com/angular-ui/ui-mask/master/demo/index.html

License: MIT License

JavaScript 100.00%

ui-mask's Introduction

ui-mask Build Status npm version Bower version Join the chat at https://gitter.im/angular-ui/ui-mask

Apply a mask on an input field so the user can only type pre-determined pattern.

PROJECT NEEDS NEW MAINTAINER!

Please reach out to Dean Sofer / ProLoser if you're interested in taking over!!!

Requirements

  • AngularJS

Usage

Bower

You can get it from Bower

bower install angular-ui-mask

Load the script files in your application:

<script type="text/javascript" src="bower_components/angular/angular.js"></script>
<script type="text/javascript" src="bower_components/angular-ui-mask/dist/mask.js"></script>

Add the specific module to your dependencies:

angular.module('myApp', ['ui.mask', ...])

NPM (CommonJS, ES6 module)

Also you can use it as CommonJS or ES6 module with any build system that supports those type of modules (Webpack, SystemJS, JSPM etc):

npm install angular-ui-mask

And then include it with

// CommonJS
var uiMask = require('angular-ui-mask');
angular.module('myApp', [uiMask, ...]);
// ES6 module
import uiMask from 'angular-ui-mask';
angular.module('myApp', [uiMask, ...]);

Customizing

You can customize several behaviors of ui-mask by taking advantage of the ui-options object. Declare ui-options as an additional attribute on the same element where you declare ui-mask.

Inside of ui-options, you can customize these five properties:

  • maskDefinitions - default: { '9': /\d/, 'A': /[a-zA-Z]/, '*': /[a-zA-Z0-9]/ },
  • clearOnBlur - default: true,
  • clearOnBlurPlaceholder - default: false,
  • eventsToHandle - default: ['input', 'keyup', 'click', 'focus']
  • addDefaultPlaceholder - default: true
  • escChar - default: '\\'
  • allowInvalidValue - default: false

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

Whereas, maskDefinitions is an object, so any custom object you supply will be merged together with the defaults using angular.extend(). This allows you to override the defaults selectively, if you wish.

When setting clearOnBlurPlaceholder to true, it will show the placeholder text instead of the empty mask. It requires the ui-mask-placeholder attribute to be set on the input to display properly.

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.

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.

Global customization

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:

app.config(['uiMask.ConfigProvider', function(uiMaskConfigProvider) {
  uiMaskConfigProvider.maskDefinitions({'A': /[a-z]/, '*': /[a-zA-Z0-9]/});
  uiMaskConfigProvider.clearOnBlur(false);
  uiMaskConfigProvider.eventsToHandle(['input', 'keyup', 'click']);
}

maskDefinitions

The keys in maskDefinitions represent the special tokens/characters used in your mask declaration to delimit acceptable ranges of inputs. For example, we use '9' here to accept any numeric values for a phone number: ui-mask="(999) 999-9999". The values associated with each token are regexen. Each regex defines the ranges of values that will be acceptable as inputs in the position of that token.

modelViewValue

If this is set to true, then the model value bound with ng-model will be the same as the $viewValue meaning it will contain any static mask characters present in the mask definition. This will not set the model value to a $viewValue that is considered invalid.

uiMaskPlaceholder

Allows customizing the mask placeholder when a user has focused the input element and while typing in their value

uiMaskPlaceholderChar

Allows customizing the mask placeholder character. The default mask placeholder is _.

Set this attribute to the word space if you want the placeholder character to be whitespace.

addDefaultPlaceholder

The default placeholder is constructed from the ui-mask definition so a mask of 999-9999 would have a default placeholder of ___-____; unless you have overridden the default placeholder character.

Testing

Most of the testing is done using Karma to run the tests and SauceLabs to provide the different browser environments to test against.

Mobile testing and debugging uses BrowserStack for its abilities to remotely debug mobile devices from a browser.

BrowserStack

Development

We use Karma and jshint to ensure the quality of the code. The easiest way to run these checks is to use gulp:

npm install -g gulp-cli
npm install && bower install
gulp

The karma task will try to open Firefox and Chrome as browser in which to run the tests. Make sure this is available or change the configuration in karma.conf.js

Gulp watch

gulp watch will automatically test your code and build a release whenever source files change.

How to release

Use gulp to bump version, build and create a tag. Then push to GitHub:

gulp release [--patch|--minor|--major]
git push --tags origin master # push everything to GitHub

Travis will take care of testing and publishing to npm's registry (bower will pick up the change automatically). Finally create a release on GitHub from the tag created by Travis.

ui-mask's People

Contributors

aidanhs avatar ajoslin avatar caiotoon avatar dandoyon avatar dhilt avatar dimrsilva avatar doogd avatar douglasduteil avatar edwardhotchkiss avatar jimallanson avatar joshkurz avatar just-boris avatar lefka avatar lukepfeiffer10 avatar marbletravis avatar mfeingold avatar petebacondarwin avatar peterox avatar pkozlowski-opensource avatar pocesar avatar powerkiki avatar proloser avatar realtica avatar shaungrady avatar solidspark avatar teamon avatar tim91084 avatar toddbranch avatar vinniefranco avatar xml avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ui-mask's Issues

Format of ui-options

Can we please see an example of ui-options? Specifically, maskDefinitions? When I try to add ui-options to a form field I am getting an error.
Uncaught TypeError: n[0].test is not a function

The form field I have looks like this.

    <input id="dob" type="text" data-ng-model="vm.dob" placeholder="Date of Birth" name="dob" data-ui-mask="19/39/2999" data-ui-mask-placeholder="" data-ui-mask-placeholder-char="_" data-ui-options="{maskDefinitions: { '1':'/[0-1]/', '2':'/[0-2]/', '3':'/[0-3]/' } }" required="required">

Any help would be appreciated.

Parser should be unshifted rather than pushed

The parser should be unshifted onto the modelCtrl.$parsers array, rather than pushed. Your directive relies on the actual $viewValue, but because the $parsers are run in array order (0, 1, 2, etc.) and your parser is pushed, it will always be the farthest parser from the viewValue and closest to the modelValue, which is obviously wrong. For example, I want to unshift a parser to convert the string to an actual Date object, but I cannot, because since you push yours mine will run before yours no matter the priority of my directive, and since yours expects a string not a Date, it won't ever be valid.

More funky placeholder behavior

I use this directive three places in our code, and unfortunately no invocation of the placeholder / ui-mask /ui-mask-placeholder attributes seem to work for all of them.

<input ui-mask="(999) 999-9999" ng-model="x" placeholder="(555) 555-5555" ui-mask-placeholder/>

<input ui-mask="99/99/9999" ng-model="y" placeholder="MM/DD/YYYY" ui-mask-placeholder/>

<input ui-mask="(999) 999-9999" ng-model="z" placeholder="Phone number" ui-mask-placeholder/>

None of these actually allow you to input text, sadly -- it gets stuck.

Removing the ui-mask-placeholder makes the MM/DD/YYYY placeholder work, surprisingly enough, but the other two for phone numbers are both broken (typing yields a mish-mash of the original placeholder text and the input text).

Am I using the new ui-mask-placeholder directive wrong? I copied the pattern from the demo.html page.

Mask date format

How to mask a date format? If I set the mask to 99/99/9999, you can input number with max 9, and I found that ui-mask execute on each character, what about if I want to limit max value from 1-31, or month to 1-12 as a date format should be?

ui-mask-placeholder (or regular placeholder) attributes get confused when typing a character in the placeholder

Splitting from issue #25

Modified plunkr example demonstrating the remaining bug:

http://plnkr.co/edit/CDG941601WdHPMEdlEdG?p=preview

Example invocation:

<input ui-mask="(999) 999-9999" ng-model="c" placeholder="Phone number" ui-mask-placeholder="(555) 555-5555"/>

Try typing in the box starting with "650" and you'll see the error -- it gets messed up if you type a key that's in the placeholder. If you enter "678987" etc it works fine.

An easier way to get masked.$viewValue?

Or at least document how masked.$viewValue is attach to [and to which] controller.
I do some testing and figured out that it would attach to the outer

tag.
but it seems it rely on other conditions. Still trying to figure out .

keep value after lost focus.

I make ui-mask for phone number, i want to keep value to validate when user click to next item while value still show for user. how ui-mask support this?

thanks,
Luan

CHANGELOG.md

Wondering if there is a changelog for tagged releases. Much easier to maintain packages in larger projects if potential breaking changes can be quickly identified. Haven't updated since 1.4.6

Comparing the readme file, looks like there are several breaking changes, is this correct?

ui mask filter

It would be great to have ui-mask-like filter.
Example:

{{1234567899 | mask: '(999) 999-9999'}} // -> (123) 456-7899

Need masking without the validation

We want to use this library but have our own validation. It would be awesome if there was an option to not set validity. Also in our case we want the model to be updated with the partially complete value this would also be a great setting.

Only valid and parse on focus out

When i start filling the input, none error are showing. But if I fulfill then with a valid string and focus out, the input is valid, it´s ok. But if I focus in again, clear the input and start filling another value, the input always shows ng-invalid-mask and ng-invalid-parse errors. I don't want this right now, because I have not finished typing the value yet. I want on focus out again.

Sorry about my English 🙈

Can't pass regular expression for maskDefinitions via ui-options

There are two issues I met so far:

  1. scope.$eval('[' + iAttrs.uiOptions + ']'); can't parse regular expressions stated directly in HTML
  2. if I use scope to define ui-options, custom maskDefinitions got overridden by angular.extend(current[i], original[i]);

Are they real issues or I'm just doing something wrong? Is there any working example how to use ui-options to override default regexes?

Save invalid data in model

Hi dudes! I want to save invalid data in model ( for notification user that he input invalid phone number for example ), but i cant because user.phone_number empty and i cant check that field filled by user or keep it empty ( not entered anything ).

%input{:type => "text", 'ng-model' => 'user.phone_number',  'ui-mask' => "+9 (999) 999-99-99", 'ui-options' => "{clearOnBlur : }"}/

clearOnBlur store entered data in input but in user model i didnt see phone_number field.

Crashes Safari if attempting to use ui-options object

So, there's a really nice undocumented feature, which is that you can override the behavior that causes the input's $viewValue to clear when the input is blurred. Simply set ui-options="{clearOnBlur: false}" as an attribute where you invoke the directive, and voilà!

Except in Safari.

In Safari, it breaks everything and you get this stack-trace:

Error: Requested keys of a value that is not an object.
keys@[native code]
extend@http://localhost:3000/bower_components/angular/angular.js:414:29
http://localhost:3000/bower_components/angular-ui-mask/dist/mask.js:126:67
uiMaskLinkingFunction@http://localhost:3000/bower_components/angular-ui-mask/dist/mask.js:132:39
invokeLinkFn@http://localhost:3000/bower_components/angular/angular.js:8290:15
nodeLinkFn@http://localhost:3000/bower_components/angular/angular.js:7800:23
compositeLinkFn@http://localhost:3000/bower_components/angular/angular.js:7149:23
compositeLinkFn@http://localhost:3000/bower_components/angular/angular.js:7152:24
publicLinkFn@http://localhost:3000/bower_components/angular/angular.js:7028:45
boundTranscludeFn@http://localhost:3000/bower_components/angular/angular.js:7167:28
controllersBoundTransclude@http://localhost:3000/bower_components/angular/angular.js:7827:35
ngIfWatchAction@http://localhost:3000/bower_components/angular/angular.js:22205:26
$digest@http://localhost:3000/bower_components/angular/angular.js:14397:31
$apply@http://localhost:3000/bower_components/angular/angular.js:14660:31
http://localhost:3000/bower_components/angular/angular.js:25880:23
dispatch@http://localhost:3000/bower_components/jquery/dist/jquery.js:4435:14

(I have to wonder if the reason this feature isn't documented is because it breaks on Safari.)

This is an angular error that's hard to find documentation on. There are a couple mentions of it on Angular's issues, but nobody puts their finger on the cause, I don't think. The cause appears to be: trying to use angular.extend() to coerce a non-object into a object.

In here (approx. lines 108-122):

// we can't use angular.copy nor angular.extend, they lack the power to do a deep merge
linkOptions = (function(original, current) {
  for (var i in original) {
    if (Object.prototype.hasOwnProperty.call(original, i)) {
      if (current[i] === undefined) {
        current[i] = angular.copy(original[i]);
      } else {
        // HERE's THE PROBLEM: We're calling angular.extend() on something that's not an object.
        angular.extend(current[i], original[i]);
      }
    }
  }
  return current;
})(options, linkOptions[0]);

we're trying to augment the default options object with any values that were supplied by the user, such as my override for clearOnBlur. I'm unclear on why the comment says we can't use angular.extend() here. In my testing, it seems to work fine.

But, if we want to stick with our current formula, I believe we can solve the problem by just dropping a few extraneous lines. Replace the block above with:

linkOptions = (function(original, current) {
    for (var i in original) {
        if (Object.prototype.hasOwnProperty.call(original, i)) {
            if (current[i] === undefined) {
                current[i] = angular.copy(original[i]);
            }
        }
    }
    return current;
})(options, linkOptions[0]);

Wherever current[i] is not undefined, we simply don't need to bother to replace it, let alone by using angular.extend(). Problem solved on Safari, and everything appears to work as intended.

Incorrectly positioned cursor in MS Edge browser

Hello

Thanks for great control, guys!

Issue is that when you place cursor in input with mask in MS Edge browser it is placed in the beginning of input. In other browsers it is correctly positioned after last filled in character.

I've tried to fix this by myself but without success.

I've created plunkr.
Try to put cursor in first input in Edge and you'll see it is before "4" character.

When initializing the mask it is set to dirty

When initializing the mask it is set to dirty even though technically the data hasn't changed.

In initPlaceHolder function eventHandler is called which ends up setting the field as dirty. It appears in other initialization sequences that we don't want it set to dirty.

Bug?

ui-mask does not play nicely with other directives

If a directive has a higher priority than ui-mask and therefore modifies the model value in it's formatter before ui-mask's formatter is executed, changing the mask dynamically does not respect the other directive. Instead ui-mask 'masks' the model value directly, NOT the value returned from the other directives formatter.

Tests fail in IE 9-11

Running the tests with sauce (or against local VMs) results in the following failing specs:

screen shot 2015-07-02 at 5 24 33 pm

I'd be happy to help troubleshoot this if you have any ideas on where to start with the mask code. Also, getting these tests running on CI would be great (happy to help set that up as well, if you have an open source Sauce account).

Mask with placeholder

Using a mask with a placeholder doesn't seem to work properly. For example if I have a phone number mask (999) 999-9999 and a placeholder Phone Number I get the following result when trying to enter phone number 123 456 7891:

P123e 456b78.

Pasting content on masked input does not remove ng-invalid-mask

Suppose I have a masked text input, and I start filling it out but don't finish. The input gains the expected ng-invalid-mask attribute. Now suppose I paste some content in the field, with enough characters to fulfill it. The input should be considered totally ng-valid, but it is not. It is keeping the ng-invalid-mask until I backspace and type in something.

Pristine is not preserved

Regardless of interaction, ui-mask immediately destroys the pristine/untouched state of input elements. In contrast, default angular directives--such as ng-required--preserve the pristine/untouched state of input elements, even when focus or blur events occur, as long as the value of the input has never changed from its original state.

For example, if I were to construct the following:

<input 
    id="ssn" 
    name="ssn" 
    type="text" 
    placeholder="123-45-6789"
    ng-model="ssn"
    ng-required="true">

The initial state of the input element, as shown by its class names, would be:

ng-pristine ng-untouched ng-invalid ng-invalid-required

And if I were to focus this input and subsequently blur it, without typing anything into it (i.e. not changing its value), both the pristine and untouched states would be preserved and I could check $dirty to hide validation errors until the input has been truly changed.

However, if I were to construct the following:

<input 
    id="ssn" 
    name="ssn" 
    type="text" 
    placeholder="123-45-6789"
    ui-mask-placeholder
    ui-mask="999-99-9999" 
    ng-model="ssn"
    ng-required="true">

Upon focus the ui.mask directive would immediately update both the input's value and the viewValue to display the mask. This will then cause the field to lose both the pristine and untouched state. And if the surrounding form was employing the ng-model option for debounce, there would be no $dirty check to hide ng-required errors.


A possible solution to this issue would be to alter both the eventHandler and blurHandler of the ui.mask source to take the following condition into consideration:

if (val.length == 0 && controller.$pristine) return;

This would essentially stop the mask from displaying on focus, but also preserve these states if a user was simply tabbing through the form, for instance.

Mask conflicts with ng-messages when invalid/valid

Suppose you had the following code for a phone number below where you are using ng-messages to display an error message saying that the field is required. If you type a phone number in and then delete the exact amount of numbers that you input you will see the "Required" message but if there are no numbers in the input and you hit the delete button again, the error messages will never come back even if you type numbers in the input and then delete them again. Not sure if this sounds confusing but its easy to replicate.

<div class="col-md-4">
        <label for="phone">
            <span class="required">*</span>&nbsp;Phone
            <span ng-messages="form.phone.$dirty && form.phone.$error" role="alert">
                <span ng-messages-include="error-messages"></span>
            </span>
        </label>
        <input type="text" class="form-control" name="phone" ng-model="formData.users.phone" model-view-value="true" ui-mask="(999) 999-9999" placeholder="(###) ###-####" ng-required="true">
    </div>


<script type="text/ng-template" id="error-messages">
        <span class="error" ng-message="required">Required</span>
        <span class="error" ng-message="email">Not a valid email address</span>
        <span class="error" ng-message="minlength">Field is too short</span>
        <span class="error" ng-message="maxlength">Field is too long</span>
        <span class="error" ng-message="min">Value is too small</span>
        <span class="error" ng-message="max">Value is too large</span>
    </script>

Binding problem with version 1.4.5

I have this example working fine on 1.4.2:

<input type="text"
            pattern="\d*"
            name="query"
            autocorrect="off"
            autocomplete="off"
            ng-if="current=='ABC'"
            ng-model="query.ABC"
            ui-mask="?99-99-999"
            model-view-value="true">

When upgraded to 1.4.5 it suddenly broke the binding with query.ABC. Even worse, it is not consistent.
I have another input right after binding to query.DEF and that one works fine.

Crashes Safari if attempting to use ui-options object

So, there's a really nice undocumented feature, which is that you can override the behavior that causes the input's $viewValue to clear when the input is blurred. Simply set ui-options="{clearOnBlur: false}" as an attribute where you invoke the directive, and voilà!

Except in Safari.

In Safari, it breaks everything and you get this stack-trace:

Error: Requested keys of a value that is not an object.
keys@[native code]
extend@http://localhost:3000/bower_components/angular/angular.js:414:29
http://localhost:3000/bower_components/angular-ui-mask/dist/mask.js:126:67
uiMaskLinkingFunction@http://localhost:3000/bower_components/angular-ui-mask/dist/mask.js:132:39
invokeLinkFn@http://localhost:3000/bower_components/angular/angular.js:8290:15
nodeLinkFn@http://localhost:3000/bower_components/angular/angular.js:7800:23
compositeLinkFn@http://localhost:3000/bower_components/angular/angular.js:7149:23
compositeLinkFn@http://localhost:3000/bower_components/angular/angular.js:7152:24
publicLinkFn@http://localhost:3000/bower_components/angular/angular.js:7028:45
boundTranscludeFn@http://localhost:3000/bower_components/angular/angular.js:7167:28
controllersBoundTransclude@http://localhost:3000/bower_components/angular/angular.js:7827:35
ngIfWatchAction@http://localhost:3000/bower_components/angular/angular.js:22205:26
$digest@http://localhost:3000/bower_components/angular/angular.js:14397:31
$apply@http://localhost:3000/bower_components/angular/angular.js:14660:31
http://localhost:3000/bower_components/angular/angular.js:25880:23
dispatch@http://localhost:3000/bower_components/jquery/dist/jquery.js:4435:14

(I have to wonder if the reason this feature isn't documented is because it breaks on Safari.)

This is an angular error that's hard to find documentation on. There are a couple mentions of it on Angular's issues, but nobody puts their finger on the cause, I don't think. The cause appears to be: trying to use angular.extend() to coerce a non-object into a object.

In here (approx. lines 108-122):

                                    // we can't use angular.copy nor angular.extend, they lack the power to do a deep merge
                                    linkOptions = (function(original, current) {
                                        for (var i in original) {
                                            if (Object.prototype.hasOwnProperty.call(original, i)) {
                                                if (current[i] === undefined) {
                                                    current[i] = angular.copy(original[i]);
                                                }
                                                else {
                                                  // HERE's THE PROBLEM: We're calling angular.extend() on something that's not an object.
                                                    angular.extend(current[i], original[i]);
                                                }
                                            }
                                        }
                                        return current;
                                    })(options, linkOptions[0]);

we're trying to augment the default options object with any values that were supplied by the user, such as my override for clearOnBlur. I'm unclear on why the comment says we can't use angular.extend() here. In my testing, it seems to work fine.

But, if we want to stick with our current formula, I believe we can solve the problem by just dropping a few extraneous lines. Replace the block above with:

linkOptions = (function(original, current) {
  for (var i in original) {
    if (Object.prototype.hasOwnProperty.call(original, i)) {
      if (current[i] === undefined) {
        current[i] = angular.copy(original[i]);
      }
    }
  }
  return current;
})(options, linkOptions[0]);

Wherever current[i] is not undefined, we simply don't need to bother to replace it, let alone by using angular.extend(). Problem solved on Safari, and everything appears to work as intended.

Model is validated only after change

I need to set the mask depending on a previous field.
So, I created a scope var to the mask definition, but the field is only validated after first interaction.

Here is a plunk: http://plnkr.co/edit/7Sk9N1x8LjJXakAtRLxb?p=preview

Apparently, the model value needs to be updated for the validation works.
I did a little trick for that on my client code:

  • change model value
  • trigger $scope.$apply()
  • restore model value
  • trigger $scope.$apply()
var original = $scope.modelValue;
$scope.modelValue = '';
$scope.$apply();
$scope.modelValue = doc;
$scope.$apply();

Original issue on ui-utils: angular-ui/ui-utils#351

DOM "change" event not fired on inputs

Minimal test case here

To reproduce type in one digit then tab out

Expected behavior: events on regular input fire keydown, input, keyup, change, blur
Actual behavior: events on ui-mask input fire keydown, input, keyup, blur

Because iElement.val(maskedValue) is called in several places, the change event never fires. Browsers only fire change events in response to user input, not in response to JavaScript setting the input's value property.

Possible fix: Observe the blur event and manually dispatch a change event when the new value is different. In that case blur will fire after change in most situations, but it is better than not firing change at all.

I'm not familiar with the code enough to be able to create a patch. A cursory glance of the code indicates that the event should probably be fired from inside the blurHandler function but it isn't obvious how to tell if the value really changed since focusing.

The use case is an autosave directive that observes change events on a parent div to catch any changes to form elements inside the div; in response to the change, the directive sends a PATCH request with the new value. The directive uses delegation so that events are captured regardless of inputs being dynamically added or removed. The directive could observe blur to catch changes, but blur events do not bubble up and the similar focusout event that does bubble is not supported in Firefox.

Weird value when using placeholder

Here's my HTML:

<input type="text" ng-model="form.phoneNumber" placeholder="Phone Number" ui-mask="(999) 999-9999" ui-mask-placeholder ui-mask-placeholder-char class="form-control">

Here's before focus:

screen shot 2015-11-19 at 11 45 42 am

Here's when focused:

screen shot 2015-11-19 at 11 45 45 am

Here's when typing:

screen shot 2015-11-19 at 11 48 06 am

What am I doing wrong? The documentation isn't very clear about how to use placeholders, I just copied the code from the demo.

main: dist/index.js is lacking

Looks like gulp remove dist/index.js file which is required in package.json as main.

Now it is broken as CommonJS dependency

Formatter should be unshifted

The formatter should be unshifted onto the modelCtrl.$formatters array, rather than pushed. The formatter expects to be the last run (closest to $viewValue), but since it is pushed it is the first run.

ui-mask stops working after running through $compile

I have a directive that's adding a name attribute to input elements that don't have a name attribute. In order for these new names to be caught by the FormController, I have to recompile the element after adding the name. However, after it's compiled you can no longer enter text into the input field.

Plunker here.

The plunk shows two directives, one which compiles, the other that doesn't.

I'm looking into reasons why this might be happening, but wanted to post the issue to see if anyone comes up with any ideas while I'm looking at it.

Problems with pasting in values

UI-Mask does not behave as expected when pasting values into input.
This is how to recreate the issue:

Scenario 1

  1. Enter value "by hand"
  2. Select whole value
  3. Paste different value to the input field

Expected behaviour:
Previous value is replaced.

Current behaviour:
Previous value is not replaced.

Scenario 2

  1. Enter part of the value
  2. Set cursor at the beggining
  3. Paste some value

Expected behaviour:
Pasted value is inserted where cursor was pointing

Current behaviour:
Pasted Value is inserted at the end of the initial value disregarding cursor position

Global Configuration

It will be nice if ui-mask have global configuration, e.g

angular
    .module('x-module')
    .config(config);

function config(UiMaskProvider) {
    UiMaskProvider.setPlaceholderChar('space');
    // another configurations
}

Then every input with ui-mask will use space as char.

Thanks.

Request: option to not unmask

I'd really like to have the masking available to aid the user, but then would also like to save/submit the value as the masked value and not unmask it.

Would it be possible to have an option for this added in the future?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.