bthurlow / nativescript-maskedinput

A {N} masked input plugin for iOS and Android
Other
8 stars 8 forks source link

Close keyboard on completing the entry #5

Closed dpdragnev closed 8 years ago

dpdragnev commented 8 years ago

Hello,

I would like to close the keyboard once the user have entered the last character in the field. Is there a way to accomplish that?

Thank you.

bthurlow commented 8 years ago

You should be able to register to the change event and compare text.length === mask.length and call dismissSoftInput when true.

I don't have time to create a working example, but when I get a chance I'll see about making one.

dpdragnev commented 8 years ago

Thanks for your quick reply. I will try your suggestion and will report back.

dpdragnev commented 8 years ago

How would you suggest to capture the change event? I tried propertyChange="{{ verifyMaskInput }}", but this event never triggered while I was typing.

bthurlow commented 8 years ago

I believe it should be propertyChange="text"

bthurlow commented 8 years ago

See https://docs.nativescript.org/core-concepts/events#propertychange-event for more info.

dpdragnev commented 8 years ago

Perfect. Thank you for your help.

The event has to be declared as propertyChange="eventHandler" and in it I did:

var obj = args.object; if (obj.text.length == obj.mask.length) { obj.dismissSoftInput(); }

This achieved the desired input.