Modifying text inside textChange nativescript
up vote
0
down vote
favorite
I'm currently using a HostListener to be able to format user text at the same time that the user is typing it. For example if the user is typing a phone number I want to be able to add format just as needed. If the string is 0000 I want the text to be 000-0, if text is 0000000000 then "(801) 123 - 1234". I got the logic to do this, but I'm currently using a hostlistener to do this.
@HostListener("textChange")
public onTextChange(target): void {
this.el.text = this.phoneFormatPipe.transform(this.el.text)
}
This works, but it keeps calling itself until the max stack call limit is reached. This is obviously too slow, so my question is: how do I modify the text inside my element without tiggering the textChange event? or is there another way to accomplish this?
Thanks in advance! Happy coding!
events nativescript angular2-nativescript angular-event-emitter
add a comment |
up vote
0
down vote
favorite
I'm currently using a HostListener to be able to format user text at the same time that the user is typing it. For example if the user is typing a phone number I want to be able to add format just as needed. If the string is 0000 I want the text to be 000-0, if text is 0000000000 then "(801) 123 - 1234". I got the logic to do this, but I'm currently using a hostlistener to do this.
@HostListener("textChange")
public onTextChange(target): void {
this.el.text = this.phoneFormatPipe.transform(this.el.text)
}
This works, but it keeps calling itself until the max stack call limit is reached. This is obviously too slow, so my question is: how do I modify the text inside my element without tiggering the textChange event? or is there another way to accomplish this?
Thanks in advance! Happy coding!
events nativescript angular2-nativescript angular-event-emitter
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm currently using a HostListener to be able to format user text at the same time that the user is typing it. For example if the user is typing a phone number I want to be able to add format just as needed. If the string is 0000 I want the text to be 000-0, if text is 0000000000 then "(801) 123 - 1234". I got the logic to do this, but I'm currently using a hostlistener to do this.
@HostListener("textChange")
public onTextChange(target): void {
this.el.text = this.phoneFormatPipe.transform(this.el.text)
}
This works, but it keeps calling itself until the max stack call limit is reached. This is obviously too slow, so my question is: how do I modify the text inside my element without tiggering the textChange event? or is there another way to accomplish this?
Thanks in advance! Happy coding!
events nativescript angular2-nativescript angular-event-emitter
I'm currently using a HostListener to be able to format user text at the same time that the user is typing it. For example if the user is typing a phone number I want to be able to add format just as needed. If the string is 0000 I want the text to be 000-0, if text is 0000000000 then "(801) 123 - 1234". I got the logic to do this, but I'm currently using a hostlistener to do this.
@HostListener("textChange")
public onTextChange(target): void {
this.el.text = this.phoneFormatPipe.transform(this.el.text)
}
This works, but it keeps calling itself until the max stack call limit is reached. This is obviously too slow, so my question is: how do I modify the text inside my element without tiggering the textChange event? or is there another way to accomplish this?
Thanks in advance! Happy coding!
events nativescript angular2-nativescript angular-event-emitter
events nativescript angular2-nativescript angular-event-emitter
asked Nov 19 at 19:03
Felipe Centeno
452513
452513
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
There is a better way to do what you're doing, but I'm not sure if there's an even better way. Coming from iOS development, I know there is definitely a more appropriate place to do this sort of manipulation, but doing it here shouldn't be causing you to reach the max stack.
If you update your source to do this instead, you will avoid the maximum stack limit (and significantly increase performance of your app). It is not the best way, but it is the best way that I have found available in NativeScript at this time.
@HostListener("textChange")
public onTextChange(target): void {
let newText: string = this.phoneFormatPipe.transform(this.el.text);
if (this.el.text !== newText) {
this.el.text = newText;
}
}
add a comment |
up vote
0
down vote
It's going to be recursive until you make sure it's not the same string with an if condition, like in @Ian's example.
Also I would suggest checking out the nativescript-masked-text-field rather formatting text manually on every change.
I tried this before, but the mask it's static. For example "(000)-000-0000" which I cannot then modified to accept more than 10 digits, or at least I don't know how. When I modified the mask programmatically it seemed to mess up with the implementation throwing some random strings.
– Felipe Centeno
Nov 19 at 19:42
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
There is a better way to do what you're doing, but I'm not sure if there's an even better way. Coming from iOS development, I know there is definitely a more appropriate place to do this sort of manipulation, but doing it here shouldn't be causing you to reach the max stack.
If you update your source to do this instead, you will avoid the maximum stack limit (and significantly increase performance of your app). It is not the best way, but it is the best way that I have found available in NativeScript at this time.
@HostListener("textChange")
public onTextChange(target): void {
let newText: string = this.phoneFormatPipe.transform(this.el.text);
if (this.el.text !== newText) {
this.el.text = newText;
}
}
add a comment |
up vote
2
down vote
accepted
There is a better way to do what you're doing, but I'm not sure if there's an even better way. Coming from iOS development, I know there is definitely a more appropriate place to do this sort of manipulation, but doing it here shouldn't be causing you to reach the max stack.
If you update your source to do this instead, you will avoid the maximum stack limit (and significantly increase performance of your app). It is not the best way, but it is the best way that I have found available in NativeScript at this time.
@HostListener("textChange")
public onTextChange(target): void {
let newText: string = this.phoneFormatPipe.transform(this.el.text);
if (this.el.text !== newText) {
this.el.text = newText;
}
}
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
There is a better way to do what you're doing, but I'm not sure if there's an even better way. Coming from iOS development, I know there is definitely a more appropriate place to do this sort of manipulation, but doing it here shouldn't be causing you to reach the max stack.
If you update your source to do this instead, you will avoid the maximum stack limit (and significantly increase performance of your app). It is not the best way, but it is the best way that I have found available in NativeScript at this time.
@HostListener("textChange")
public onTextChange(target): void {
let newText: string = this.phoneFormatPipe.transform(this.el.text);
if (this.el.text !== newText) {
this.el.text = newText;
}
}
There is a better way to do what you're doing, but I'm not sure if there's an even better way. Coming from iOS development, I know there is definitely a more appropriate place to do this sort of manipulation, but doing it here shouldn't be causing you to reach the max stack.
If you update your source to do this instead, you will avoid the maximum stack limit (and significantly increase performance of your app). It is not the best way, but it is the best way that I have found available in NativeScript at this time.
@HostListener("textChange")
public onTextChange(target): void {
let newText: string = this.phoneFormatPipe.transform(this.el.text);
if (this.el.text !== newText) {
this.el.text = newText;
}
}
answered Nov 19 at 19:19
Ian MacDonald
8,38811230
8,38811230
add a comment |
add a comment |
up vote
0
down vote
It's going to be recursive until you make sure it's not the same string with an if condition, like in @Ian's example.
Also I would suggest checking out the nativescript-masked-text-field rather formatting text manually on every change.
I tried this before, but the mask it's static. For example "(000)-000-0000" which I cannot then modified to accept more than 10 digits, or at least I don't know how. When I modified the mask programmatically it seemed to mess up with the implementation throwing some random strings.
– Felipe Centeno
Nov 19 at 19:42
add a comment |
up vote
0
down vote
It's going to be recursive until you make sure it's not the same string with an if condition, like in @Ian's example.
Also I would suggest checking out the nativescript-masked-text-field rather formatting text manually on every change.
I tried this before, but the mask it's static. For example "(000)-000-0000" which I cannot then modified to accept more than 10 digits, or at least I don't know how. When I modified the mask programmatically it seemed to mess up with the implementation throwing some random strings.
– Felipe Centeno
Nov 19 at 19:42
add a comment |
up vote
0
down vote
up vote
0
down vote
It's going to be recursive until you make sure it's not the same string with an if condition, like in @Ian's example.
Also I would suggest checking out the nativescript-masked-text-field rather formatting text manually on every change.
It's going to be recursive until you make sure it's not the same string with an if condition, like in @Ian's example.
Also I would suggest checking out the nativescript-masked-text-field rather formatting text manually on every change.
answered Nov 19 at 19:35
Manoj
3,1331916
3,1331916
I tried this before, but the mask it's static. For example "(000)-000-0000" which I cannot then modified to accept more than 10 digits, or at least I don't know how. When I modified the mask programmatically it seemed to mess up with the implementation throwing some random strings.
– Felipe Centeno
Nov 19 at 19:42
add a comment |
I tried this before, but the mask it's static. For example "(000)-000-0000" which I cannot then modified to accept more than 10 digits, or at least I don't know how. When I modified the mask programmatically it seemed to mess up with the implementation throwing some random strings.
– Felipe Centeno
Nov 19 at 19:42
I tried this before, but the mask it's static. For example "(000)-000-0000" which I cannot then modified to accept more than 10 digits, or at least I don't know how. When I modified the mask programmatically it seemed to mess up with the implementation throwing some random strings.
– Felipe Centeno
Nov 19 at 19:42
I tried this before, but the mask it's static. For example "(000)-000-0000" which I cannot then modified to accept more than 10 digits, or at least I don't know how. When I modified the mask programmatically it seemed to mess up with the implementation throwing some random strings.
– Felipe Centeno
Nov 19 at 19:42
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53381062%2fmodifying-text-inside-textchange-nativescript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown