please add keypress event before input textfield, thx
Hi @Nurgunkalol,
Can you provide more info about your case and what did you mean by adding keypress event before input TextField? If you need to check, when the TextField is selected, you can use the tap event.
@tsonevn i want to get event between tap symbol on keyboard and input it on textfield, something like keypress listener on my textfield
Hi @Nurgunkalol,
You can use the textChange event, which will be fired on every key tap in the keyboard. For example:
<TextField hint="Enter text" text="" (textChange)="textChangeM($event)"></TextField>
@tsonevn ye, im already using it but its not what i want, its anyways shows at first which value i taped, then i need to change it. Im tryed to make logic like hidden textfield + label with same value, but in GridLayout ios label closes textfield and i cant tap textfield. I have a task to make textfield only numeric 0-9, without "." and "-" value, i want to disable that values in keyboard of my textfield
Hi @Nurgunkalol.
In your scenario, you can use nativescript-maskedinput, which allows you to set up specific input format for the entered text.
Another option is to use Angular forms validation, which can help you to validate the content. In this scenario, you can also create custom form validators.
@tsonevn how to catch keyboard clear button if textfield is empty ?
if the textField is empty none of the provided strategies provide a way to capture back/del keypress
HI @luckyape,
Please, provide a sample project, which demonstrates the issue, you are facing.
@tsonevn Maybe @luckyape has no issue. But is it possible to capture a key press in nativescript (in general) or in particular in a textfield like @luckyape says?
For instance if you have 2 fields and you want to navigate from one to another based on the user input, if you want to navigate from the second field(having no value in it) to the first field when you press backspace on the softinput, how can you do that?
if you have 2 fields and you want to navigate from one to another based on the user input, if you want to navigate from the second field(having no value in it) to the first field when you press backspace on the softinput, how can you do that? - Same requirement. How to identify whether the user pressed backspace on keyboard!
Is there a way to capture key events like the clear event from keyboard on especially for empty text fields? @tsonevn
@virtualbjorn did you find how to capture clear event for empty text fields?
For android, yes. I was able to get it. I opened a feature request and is being worked on atm and mostly works on android.
@virtualbjorn can you share the code?
You can follow the instructions here.
https://github.com/NativeScript/NativeScript/issues/7349#issuecomment-501635567
thanks @virtualbjorn, it works for Android!
For iOS i didn't find any solution, textFieldShouldChangeCharactersInRangeReplacementString doesn't trigger whene textField is empty. Did you find any solution?
Unfortunately, I haven't found a way for iOS. Though I found some kind of a workaround native iOS and I don't have that much swift/obj-c skills so I'm kinda stuck on that too
Most helpful comment
@tsonevn Maybe @luckyape has no issue. But is it possible to capture a key press in nativescript (in general) or in particular in a textfield like @luckyape says?
For instance if you have 2 fields and you want to navigate from one to another based on the user input, if you want to navigate from the second field(having no value in it) to the first field when you press backspace on the softinput, how can you do that?