Home > Mobile >  Codename one create a PIN constraint
Codename one create a PIN constraint

Time:11-05

Am creating a form with some Text inputs where a user can update their PIN, so i need the inputs to be only numeric and also kind a password- masked. I've tried this here but it only makes the input masked and accepts even characters,

TextComponent currentPIN = new TextComponent().labelAndHint("Current Pin").constraint(TextArea.NUMERIC).constraint(TextArea.PASSWORD);
        TextComponent newPIN = new TextComponent().labelAndHint("New PIN").constraint(TextArea.NUMERIC).constraint(TextArea.PASSWORD);
        TextComponent confirmPIN = new TextComponent().labelAndHint("Confirm PIN").constraint(TextArea.NUMERIC).constraint(TextArea.PASSWORD);

how can I achieve this, I want the input to accept only PIN, that's numeric and be masked.

CodePudding user response:

You cannot chain calls to constraint() that way and have them add up.

From the Javadoc (my emphasis):

public void setConstraint(int constraint)

Sets the constraint which provides a hint to the virtual keyboard input, notice this doesn't limit input type in any way!

Parameters: constraint - one of ANY, EMAILADDR, NUMERIC, PHONENUMBER, URL, DECIMAL it can be bitwised or'd with one of PASSWORD, UNEDITABLE, SENSITIVE, NON_PREDICTIVE, INITIAL_CAPS_SENTENCE, INITIAL_CAPS_WORD. E.g. ANY | PASSWORD.

The proper form is

...constraint(TextArea.NUMERIC | TextArea.PASSWORD)
  • Related