Discussion:
Text entry limitation
Jean-Luc Arnaud
2017-08-18 08:35:04 UTC
Permalink
Hi all,

What's the best way to limit text entry to only some characters?

Mask property doesn't seem to be the solution.

Of course, I could code for a kind of filter, but in addition to
authorized characters, I would have to manage Enter, Return, Tab,
arrows, Delete, ...

Any suggestion welcome.
--
Jean-Luc Arnaud




To unsubscribe, email ***@xojo.com
roland
2017-08-18 09:14:37 UTC
Permalink
I use the property limitText of a textfield.

For the special character I use (this will be the filter)
AddHandler tf101(fn).keypressed, AddressOf myMethod

Roland
Post by Jean-Luc Arnaud
Hi all,
What's the best way to limit text entry to only some characters?
Mask property doesn't seem to be the solution.
Of course, I could code for a kind of filter, but in addition to
authorized characters, I would have to manage Enter, Return, Tab,
arrows, Delete, ...
Any suggestion welcome.
To unsubscribe, email ***@xojo.com
Jean-Luc Arnaud
2017-08-18 16:13:21 UTC
Permalink
Thanks for the reply, Roland.

It's not exactly my need. Nevertheless, I'm interested in your use of
AddHandler, but don't understand it.

Where do you place this code?

What does tf101(fn) represent?

Thanks for further information.

Jean-Luc Arnaud
Post by roland
I use the property limitText of a textfield.
For the special character I use (this will be the filter)
AddHandler tf101(fn).keypressed, AddressOf myMethod
Roland
Post by Jean-Luc Arnaud
Hi all,
What's the best way to limit text entry to only some characters?
Mask property doesn't seem to be the solution.
Of course, I could code for a kind of filter, but in addition to
authorized characters, I would have to manage Enter, Return, Tab,
arrows, Delete, ...
Any suggestion welcome.
To unsubscribe, email ***@xojo.com
Roland Brouwers
2017-08-18 17:17:13 UTC
Permalink
I create a class with super = textfield = > myTextfield()

If there are x textfields on the window, I will drag x times this
myTextfield in the window. myTextfield(0),myTextfield(1)....
(They are all members of an array of myTextfields(), you can define this
in the editor)

Every myTextfield() has a handler keydown(Desktop) or keypressed(Web)

So
*AddHandler tf101(fn).keypressed, AddressOf myMethod*
This will be defined in the open event of the window
fn = total number of myTextfield()
A for next loop will go through all myTextfields and for every myTextfield() the method 'myMethod' will be executed.
Therefor in myMethod we will*test every char.*
if asc(key)=13 or asc(key)=3 or asc(key)=9 then
goto next field
else
do something
end if

I hope you can understand this explanation.

Roland Brouwers

C.A.T. bvba
Zevenbergenlaan 16
B-2660 Antwerpen-Hoboken
Belgium
Mob: +32 475 443 105
Post by Jean-Luc Arnaud
Thanks for the reply, Roland.
It's not exactly my need. Nevertheless, I'm interested in your use of
AddHandler, but don't understand it.
Where do you place this code?
What does tf101(fn) represent?
Thanks for further information.
Jean-Luc Arnaud
Post by roland
I use the property limitText of a textfield.
For the special character I use (this will be the filter)
AddHandler tf101(fn).keypressed, AddressOf myMethod
Roland
Post by Jean-Luc Arnaud
Hi all,
What's the best way to limit text entry to only some characters?
Mask property doesn't seem to be the solution.
Of course, I could code for a kind of filter, but in addition to
authorized characters, I would have to manage Enter, Return, Tab,
arrows, Delete, ...
Any suggestion welcome.
To unsubscribe, email ***@xojo.com
Jean-Luc Arnaud
2017-08-21 07:39:40 UTC
Permalink
Clear, thank you.

Jean-Luc Arnaud
Post by Roland Brouwers
I create a class with super = textfield = > myTextfield()
If there are x textfields on the window, I will drag x times this
myTextfield in the window. myTextfield(0),myTextfield(1)....
(They are all members of an array of myTextfields(), you can define
this in the editor)
Every myTextfield() has a handler keydown(Desktop) or keypressed(Web)
So
*AddHandler tf101(fn).keypressed, AddressOf myMethod*
This will be defined in the open event of the window
fn = total number of myTextfield()
A for next loop will go through all myTextfields and for every myTextfield() the method 'myMethod' will be executed.
Therefor in myMethod we will*test every char.*
if asc(key)=13 or asc(key)=3 or asc(key)=9 then
goto next field
else
do something
end if
I hope you can understand this explanation.
Roland Brouwers
C.A.T. bvba
Zevenbergenlaan 16
B-2660 Antwerpen-Hoboken
Belgium
Mob: +32 475 443 105
Post by Jean-Luc Arnaud
Thanks for the reply, Roland.
It's not exactly my need. Nevertheless, I'm interested in your use of
AddHandler, but don't understand it.
Where do you place this code?
What does tf101(fn) represent?
Thanks for further information.
Jean-Luc Arnaud
Post by roland
I use the property limitText of a textfield.
For the special character I use (this will be the filter)
AddHandler tf101(fn).keypressed, AddressOf myMethod
Roland
Post by Jean-Luc Arnaud
Hi all,
What's the best way to limit text entry to only some characters?
Mask property doesn't seem to be the solution.
Of course, I could code for a kind of filter, but in addition to
authorized characters, I would have to manage Enter, Return, Tab,
arrows, Delete, ...
Any suggestion welcome.
To unsubscribe, email ***@xojo.com
Markus Winter
2017-08-21 08:37:52 UTC
Permalink
Post by Roland Brouwers
A for next loop will go through all myTextfields and for every myTextfield() the method 'myMethod' will be executed.
Why? Seems quite wasteful.

MfG

Markus

Sent from my iPad



To unsubscribe, email ***@xojo.com
roland
2017-08-21 09:08:59 UTC
Permalink
I don't understand the 'Why'

It is obvious that I have to test every TextField on the window. Every
TextField has parameters which are found in the database. Every time you
enter a TextField I have to check for CR, TAB, ENTER. Also I check if
all keyfields are entered, which will lead to a lookup in the database
for the record. Every field can have a different default value or an
after-input processing.......I could put much of this pre and post
processing in the class tf101() as a standard, but till now I'm little
bit undecided.

Mfg

Roland
Post by Markus Winter
Post by Roland Brouwers
A for next loop will go through all myTextfields and for every myTextfield() the method 'myMethod' will be executed.
Why? Seems quite wasteful.
MfG
Markus
Sent from my iPad
To unsubscribe, email ***@xojo.com
Markus Winter
2017-08-21 09:27:19 UTC
Permalink
Post by roland
It is obvious that I have to test every TextField on the window.
No. That's what the TextChange event is for.
Post by roland
Every TextField has parameters which are found in the database. Every time you enter a TextField I have to check for CR, TAB, ENTER. Also I check if all keyfields are entered, which will lead to a lookup in the database for the record. Every field can have a different default value or an after-input processing.......I could put much of this pre and post processing in the class tf101() as a standard, but till now I'm little bit undecided.
That is a VERY different usage scenario from the question being asked. If you need to check each TextField if data have been entered that's one thing, if you need to restrict data entry to a certain format then that is quite another.

MfG

Markus

Sent from my iPad


To unsubscribe, email ***@xojo.com
Jean-Luc Arnaud
2017-08-21 09:32:19 UTC
Permalink
You're right, Markus, and it's what I meant writing "It's not exactly my
need." in a previous reply to Roland.

Nevertheless, this answer seemed interesting enough for requesting
additional info (for a further project, maybe...).

Many thanks for all replyers.

Jean-Luc Arnaud
Post by Markus Winter
Post by roland
It is obvious that I have to test every TextField on the window.
No. That's what the TextChange event is for.
Post by roland
Every TextField has parameters which are found in the database. Every time you enter a TextField I have to check for CR, TAB, ENTER. Also I check if all keyfields are entered, which will lead to a lookup in the database for the record. Every field can have a different default value or an after-input processing.......I could put much of this pre and post processing in the class tf101() as a standard, but till now I'm little bit undecided.
That is a VERY different usage scenario from the question being asked. If you need to check each TextField if data have been entered that's one thing, if you need to restrict data entry to a certain format then that is quite another.
MfG
Markus
Sent from my iPad
To unsubscribe, email ***@xojo.com

emile.a.schwarz
2017-08-18 09:15:30 UTC
Permalink
InStr ?

 

If InStr(TextField1.Text,"LIST OF VALID CHARACTERS") > 0 Then

// Deal with the valid character(s)

 

Else

// No nothing: reject other characters

End If

 

I do that to keep A-Z and 0-9 characters in a project. Works fine (I hope).

 

Emile

 

 
Message du 18/08/17 10:35
De : "Jean-Luc Arnaud"
A : "Nug"
Objet : Text entry limitation
Hi all,
What's the best way to limit text entry to only some characters?
Mask property doesn't seem to be the solution.
Of course, I could code for a kind of filter, but in addition to
authorized characters, I would have to manage Enter, Return, Tab,
arrows, Delete, ...
Any suggestion welcome.
--
Jean-Luc Arnaud
To unsubscribe, email ***@xojo.com
Markus Winter
2017-08-18 09:23:34 UTC
Permalink
Post by emile.a.schwarz
If InStr(TextField1.Text,"LIST OF VALID CHARACTERS") > 0 Then
// Deal with the valid character(s)
Else
// No nothing: reject other characters
End If
That's a srart but not sufficient. The user will still be able to paste or drag and drop invalid characters.

Markus




To unsubscribe, email ***@xojo.com
emile.a.schwarz
2017-08-18 11:53:30 UTC
Permalink
You have a good point Markus.

 

In my context (the user does not enter anything, the text already exists), this works. I typer too fast and think too slow :(

 

Emile

 

PS: I continue like that the whole morning (today is a bad day for me).

 
Message du 18/08/17 11:23
De : "Markus Winter"
A : "Nug"
Objet : Re: Text entry limitation
If InStr(TextField1.Text,"LIST OF VALID CHARACTERS") > 0 Then
// Deal with the valid character(s)
Else
// No nothing: reject other characters
End If
That's a srart but not sufficient. The user will still be able to paste or drag and drop invalid characters.
Markus
To unsubscribe, email us here.
To unsubscribe, email ***@xojo.com
Jean-Luc Arnaud
2017-08-18 16:17:51 UTC
Permalink
You're right.

In addition, what about Return, Enter, Del, arrows, ...?

I finally coded that in the KeyDown event of a TextField control:

Select Case Key

Case "I","V","X","L","C","D","M", Chr(13), Chr(3), Chr(127)
Return False

Case Chr(9)
Décimal_TextField.SetFocus
Return True

Case Is>=Chr(32)
Return True

End Select

This matches exactly my need (except for Drag/Drop and Paste).

Thanks to all replyers

Jean-Luc Arnaud
Post by Markus Winter
Post by emile.a.schwarz
If InStr(TextField1.Text,"LIST OF VALID CHARACTERS") > 0 Then
// Deal with the valid character(s)
Else
// No nothing: reject other characters
End If
That's a srart but not sufficient. The user will still be able to
paste or drag and drop invalid characters.
Markus
To unsubscribe, email ***@xojo.com
Marnaud
2017-08-18 16:28:47 UTC
Permalink
Post by Jean-Luc Arnaud
Select Case Key
Case "I","V","X","L","C","D","M", Chr(13), Chr(3), Chr(127)
Return False
Case Chr(9)
Décimal_TextField.SetFocus
Return True
Case Is>=Chr(32)
Return True
End Select
This matches exactly my need (except for Drag/Drop and Paste).
I usually do something like that. The notable difference being I use Select case Asc(Key) instead of comparing against Chr (this is the other way around, but I do like that because the language reference state that Chr returns character as ASCII values and I have seen cases where the equality wasn’t true).

As I understand, you’re trying to only accept roman characters, right?

Why do you handle the chr(9) like this? The tab key should just work if you return false (and don’t forger if the user is actually typing Shift-Tab to move the focus to the previous field!)

Also, Is>=Chr(32) is redundant with Chr(13) and chr(3) returning false. I’m just saying that to improve the piece of code above.

Regards


To unsubscribe, email ***@xojo.com
Jean-Luc Arnaud
2017-08-21 08:05:51 UTC
Permalink
Hi Arnaud
I use Select case Asc(Key) instead of comparing against Chr...I have
seen cases where the equality wasn’t true
Thanks for this information, I didn't know that.
As I understand, you’re trying to only accept roman characters, right?
Right !
Why do you handle the chr(9) like this?
Nothing to do with filtering characters. I just want to be sure that Tab
will give focus to the specified field.
(and don’t forger if the user is actually typing Shift-Tab to move the
focus to the previous field!)
And, of course, I forgot it! Thanks for pointing that. Actually, the
case Is>=Chr(32) lets the Shift-Tab works properly.
Also, Is>=Chr(32) is redundant with Chr(13) and chr(3) returning
false. I’m just saying that to improve the piece of code above.
I don't think so. It's the part of the filter that deal with any other
character except those previously filtered. It could be replaced par the
'Else' part of the Select Case test. This lets the TextField not
accepting any character >=Chr(32), but working as usual for the others,
like arrows, Shift-Tab, ...


Jean-Luc Arnaud
Le 18 août 2017 à 18:17 du soir, Jean-Luc Arnaud
Post by Jean-Luc Arnaud
Select Case Key
Case "I","V","X","L","C","D","M", Chr(13), Chr(3), Chr(127)
Return False
Case Chr(9)
Décimal_TextField.SetFocus
Return True
Case Is>=Chr(32)
Return True
End Select
This matches exactly my need (except for Drag/Drop and Paste).
I usually do something like that. The notable difference being I use
Select case Asc(Key) instead of comparing against Chr (this is the
other way around, but I do like that because the language reference
state that Chr returns character as ASCII values and I have seen cases
where the equality wasn’t true).
As I understand, you’re trying to only accept roman characters, right?
Why do you handle the chr(9) like this? The tab key should just work
if you return false (and don’t forger if the user is actually typing
Shift-Tab to move the focus to the previous field!)
Also, Is>=Chr(32) is redundant with Chr(13) and chr(3) returning
false. I’m just saying that to improve the piece of code above.
Regards
To unsubscribe, email ***@xojo.com
Loading...