Skip to main content

TextField containing a phone number in international format

6 replies [Last post]
ugochirico
Offline
Joined: 2009-11-04
Points: 0

Hi,
I'm trying to create a TextField containing a phone number in international format, i.e. a number containing +0123456789.
I tried in this way:

m_number.setConstraint(TextField.PHONENUMBER);
m_number.setInputMode("123");
m_number.setInputModeOrder(new String[] {"123"});

but I'm not able to digit '+', needed for international numbers, in any way.

I googled a lot to find a solution but I wasn't lucky.
Can someone suggest me how to do that?

Thanks in advance,
Ugo Chirico
http://www.ugosweb.com

Message was edited by: ugochirico

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ugochirico
Offline
Joined: 2009-11-04
Points: 0

hi again,

i tried to add
number.setCommitTimeout(1);
and the problem related to the slowness seems solved.

I'm investigating...

Ugo

vprise
Offline
Joined: 2003-11-07
Points: 0

You need to add a new "language" to the text field and select it as the input mode. See the addInputMode method.

ugochirico
Offline
Joined: 2009-11-04
Points: 0

Hi, thanks for the answer.
But there is something that doesn't work yet.
I tried with this:

Hashtable phonenum = new Hashtable();
phonenum.put(new Integer('0'), "0" );
phonenum.put(new Integer('9'), "9" );
phonenum.put(new Integer('8'), "8" );
phonenum.put(new Integer('7'), "7" );
phonenum.put(new Integer('6'), "6" );
phonenum.put(new Integer('5'), "5" );
phonenum.put(new Integer('4'), "4" );
phonenum.put(new Integer('3'), "3" );
phonenum.put(new Integer('2'), "2" );
phonenum.put(new Integer('1'), "1" );
phonenum.put(new Integer('#'), "+" );
TextField.addInputMode("+123", phonenum, false);

m_number.setConstraint(TextField.PHONENUMBER);
m_number.setInputMode("+123");
m_number.setInputModeOrder(new String[] {"+123"});

The first issue is:
I see that if I use TextField.PHONENUMBER constraint the + cannot be typed yet, but if I use TextField.DECIMAL I can type + by typing on # key.
I see that in the TextField.java source code there is a control upon the constraint that doesn't allow to type + if the constraint is different from NUMBER. So I partially solved by using TextField.DECIMAL.

The second issue is:
I tried by mapping + with # key. This partially works because different handsets have + is on different keys. For example, on nokia the + is near to * while on SonyEricsson + is near to 0. In order to give the same user experience as the rest of the phone, the + should be on the same key where it is printed on.

The third issue is:
While I type numbers only, I can type them fast, but, as soon as I type the +, something happens in the text field and the typing become much slower. I see that if I type a key twice (i.e. 00) the second key has not typed. To type two consecutive 0 I have to wait a sec after the first digit.
It seems as the + wakes up the "language" beyound the text field and something like the "abc" behaviour starts (i.e. the behaviour that allows me to type b by typing twice on 2).

any help or suggestion is really apprecciated.

Ugo

vprise
Offline
Joined: 2003-11-07
Points: 0

Hi,
I don't see the line in TextField where + is blocked? Can you be specific?

There might be a problem related to using the # key since it is assumed to be the input mode change key. You can either use setDefaultChangeInputModeKey('*') temporarily or instead override isChangeInputMode to always return false.

About the slowness issue, I would assume this is probably related to an exception or something of the sort. If you have code to reproduce this please file a bug in the project issue tracker and we will take a look at it.

ugochirico
Offline
Joined: 2009-11-04
Points: 0

hi,
the block is in TextField.java in the method:
public void insertChars(String c)
in line 754 I see
if ((getConstraint() & TextArea.NUMERIC) != 0) {
if(c.charAt(0) < '0' || c.charAt(0) > '9'){
return;
}
}

because NUMERIC = 2 and PHONENUMBER = 3 getConstraint() & TextArea.NUMERIC = 1, the condition is > 0 and + is discarded.

Then, I tried by overriding isChangeInputMode as you suggest but nothing changed.

Later I'll prepare a peice of code to reproduce the problem an I'll post a bug in the issue tracker.

Finally, what about the second issue (different positions where + is placed on different phones)?

Thanks again,

Ugo

vprise
Offline
Joined: 2003-11-07
Points: 0

I fixed this in SVN