How to set autoclear on angular ui-mask to false?
Asked Answered
J

3

7

I currently have an input with a ui-mask for a phone. If the value that is inputted isn't the full length of the mask, it clears the input. Is there a way to set the ui-mask so that it doesn't clear the input upon clicking or losing focus?

<input ui-mask="(999) 999-9999" type="text"/>
Jackson answered 19/12, 2014 at 21:31 Comment(5)
You can do it using javacsript and Angular. But I am thinking why you need to override ui-mask actual functionality. What wil be the purpose of using ui-mask then.Classicism
Because I also have validation for different sizes of phones, its just an easy way to input the values.Jackson
you can combine different validation in ui-mask..Classicism
As in ng-maxlength and ng-minlength but also different type of regex validations?Jackson
I am posting an example.Classicism
W
17

You can set a ui-options attribute that sets the option:

<input ui-mask="(999) 999-9999" ui-options="{clearOnBlur: false}" type="text" />
Wastrel answered 1/4, 2015 at 1:16 Comment(0)
J
0

I didn't really find the exact answer I wanted but this is the solution I went with.

<input ui-mask="?(999) 999-9999" type="text"/>

Just so I could use the ui-mask and it wouldn't clear the field.

Jackson answered 22/12, 2014 at 17:36 Comment(2)
Same issue, but with this solution it does not return an "invalid" on $error since the entire mask is optional.Charlacharlady
True, but I was able to add my own $errors and check for lengths.Jackson
C
0

Per the docs, you can achieve this globally in your application using app.config()and the options available:

app.config(['uiMask.ConfigProvider', function(uiMaskConfigProvider) {
  uiMaskConfigProvider.clearOnBlur(false);
}]);

Here's the full list of options: ui-mask options

Contrabandist answered 4/5, 2018 at 14:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.