Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: mask texts without an selector (AngularJS) #306

Closed
sergiomichels opened this issue Jun 6, 2015 · 13 comments
Closed

Feature request: mask texts without an selector (AngularJS) #306

sergiomichels opened this issue Jun 6, 2015 · 13 comments

Comments

@sergiomichels
Copy link

It would be nice to be able to mask not only inputs but also texts. This is a good feature to use when this plugin is integrated with AngularJS filters, for example:

2023490090 | mask: '000.000.000-00'

This can be accomplished by adapting the getMasked method to accept text values. The jQuery usage could be

$.masked(2023490090, '000.000.000-00')

I will try to reserve some time this week to make a pull request :-)

@igorescobar
Copy link
Owner

JQuery Mask works with text elements too. There is some examples at our home page.

[]'s
Igor

On 06/06/2015, at 17:45, Sérgio Michels [email protected] wrote:

It would be nice to be able to mask not only inputs but also texts. This is a good feature to use when this plugin is integrated with AngularJS filters, for example:

2023490090 | mask: '000.000.000-00'

This can be accomplished by adapting the getMasked method to accept text values. The jQuery usage could be

$.masked(2023490090, '000.000.000-00')

I will try to reserve some time this week to make a pull request :-)


Reply to this email directly or view it on GitHub.

@sergiomichels
Copy link
Author

Right, but it works without an element like my example?

@igorescobar
Copy link
Owner

Essentially, nothing will work without an selector. Everything depends upon it.

[]'s
Igor

On 06/06/2015, at 18:47, Sérgio Michels [email protected] wrote:

Right, but it works without an element like my example?


Reply to this email directly or view it on GitHub.

@sergiomichels
Copy link
Author

The function that I mentioned can be easily changed to work without selectors...

@igorescobar igorescobar changed the title Feature request: mask texts Feature request: mask texts without an selector (AngularJS) Jun 9, 2015
@igorescobar
Copy link
Owner

@sergiomichels I know that :-) I'm just explaining why it will not work without an selector. This should be implemented because it's not ready to work without an selector. This feature should be well designed so don't need to hurry ;-)

@sergiomichels
Copy link
Author

Ok, got it! My hurry is to not duplicate code or customize it in the project without really needing. Nothing good comes with some hidden customized code that a few knows

@igorescobar
Copy link
Owner

Sure, what we need to have in mind is that it should be generic, relying only on jQuery and vanilla javascript behaviours...never specifically related or dependent on a angular or any other framework. You should probably know that I'm just being as much clear as possible 👍

@sergiomichels
Copy link
Author

Yes, Angular is just an example of use case and the mask plugin should not depend on it. My final suggestion ($.masked) could be used by anyone.

@rodolfojnn
Copy link

+1 for this feature. As a hack, I have made:

$('<p>4326345645343</p>').mask('000.000.000-00').text()

@schleumer
Copy link

I have the same problem too, it's not only about Angular. I need to do this workarround:

$(element.find('input')[0]).mask(`#.##0,00`, {reverse: true})

To mask only bind to the element inside element variable, which is an template compiled on the fly and not available on document.

element.find('input')[0] will bring the first DOMElement(which is a native element) from the jQuery's elements array. And $(...) will create another jQuery array with that element and will unbind from the input selector, which will make the plugin work "as expected".

And this exemple:

element.find('input').mask(...)

will bind to all input elements on the entire document.


Another workaround is too disable $.jMaskGlobals.watchInputs, placing:

$.jMaskGlobals.watchInputs = false

Before angular stuffs.


Also, Angular's core works on jQuery, so, all elements on Angular if jQuery is available are also a jQuery element and supports jQuery plugins too.

@settysreekanth
Copy link

FYI -I happened to do it in the following way in my angular application..
element.val(some_value).mask('AAA-AAA')

PS: In my case, element was input type.

@igorescobar
Copy link
Owner

Guys:
#499

Also... the method .masked is already available.

Any other example on alternatives on how to integrate it would be appreciated.

@sergiomichels
Copy link
Author

@igorescobar Your example is just for directives, and with this type of component it plays nice.

My request was for filters, when I do not have an instance of an element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants