Text field - limit the input

How do you limit a users input on a text field?

I have text field with a format mask of

#####.####

I have also tried to set the format in form designer on the field but both formats are not setting a limit on inputs.

Any suggestions would be much appreciated.

Thank you

If for limit you mean the number of chars that the user can input you just need to size your db column accordingly, ex.: a varchar(10) will not allow more than 10 chars typed into any field associated with it, if the user types more it gets a beep and nothing else.

To complete my answer keep in mind that the format that you can apply to a filed in a form (ex.: #####.####) is just a visual thing, the data saved to the db is not affected.

Thank you ngervasi

The database field is a number. In the database the length is 22 with a precision of 10 and a datascale of 5. In servoy it is specifying length as 10,5 but I can enter way more chars than that.

I am a little confused as to why the default format wouldn’t handle the size of the input and am even more puzzled as to why I would need to modify the database to make this work. We are not concerned with the database settings, as our input formats should conform to the database field in which the data is being entered.

Its an input field that needs to have a format mask to control the length and type of input.

Is there not a way for us to do this in servoy?

Oh, it’s a number field then? In you first post you were referring to a “text field”.
For number fields it’s a bit tricky, if I remember correctly Servoy simply rounds the number on save but I’m not 100% sure, you should do some testing comparing what you enter in the field and what gets saved to the db.

I almost forgot about Validators!
You can use a validator to check the number that the user entered in the field, the servoy.NumberRangeValidator nicely fits your needs.
To define a validator open the db table in the database servers node, select the column and select the Validation tab.
Hope it helps.

Thanks ngervasi,

To clarify, it is a number dataprovider and a text field on the form level.

I have tried the range validator, and it only seems to work when the text field loses focus. After an attempted save, the validation seems to disappear completely.

Are there any built in functions that would only allow a user to enter a number within a range, and not allow the user to enter anything greater than a specified value?

I am finding it very frustrating that simple functionality like this isn’t present in servoy.

Are there any built in functions that would only allow a user to enter a number within a range, and not allow the user to enter anything greater than a specified value?

Not that I know, you could create a case in the support system if you think that validators are not behaving correctly.

what do you exactly want for numbers, do you want to fix the number of chars that can be typed? or what it represents?

so do you want

→ allows from 0->9999

or do you want to say only a range like between 4444-9444

a range can only really be validated when the user goes out of the text field. (so use the range validator for this)

The first is currently not something we support because the format string is just how it should display (like #,###.00) it but it supports bigger numbers

ngervasi:
If for limit you mean the number of chars that the user can input you just need to size your db column accordingly, ex.: a varchar(10) will not allow more than 10 chars typed into any field associated with it, if the user types more it gets a beep and nothing else.

I tried like this with Servoy 6.0, but it seems to not work as expected. The Size of the Dataprovider (even if is a Variable or a Table-Field) is 3, but the Textfield doesn’t stop after 3 characters (scrolls inside the field).

How can I control, how many characters the user can type into a Textfield (even if is a Variable or a Table-Field) ?
Do I really have to manually code it with onDataChange ?

i can’t reproduce this.
If i create a table text/varchar column with max 3 and i place that as a TextField on th form, i can’t type more then 3 chars into it in web or smart client.

jcompagner:
i can’t reproduce this.
If i create a table text/varchar column with max 3 and i place that as a TextField on th form, i can’t type more then 3 chars into it in web or smart client.

hmmm… I tried again… and as you wrote: I can’t type more then 3 chars :roll:

maybe I was confused during testing/switching between Variable- and Foundset-Dataprovider.
So, if I understand right: Controll of the chars size is possible, but only with a Table as
Dataprovider ?

Thank you !

pure javascript variables (like globals or form) don’t have a length.

jcompagner:
pure javascript variables (like globals or form) don’t have a length.

Yes this is true, but what I’m missing is a kind of “input-mask”.
I tried to build this kind of functionality with the onDataChange,
but unfortunately the onDataChange Event fires only if the user
hits Enter and not after every typing, so the second thing I miss
is a “OnKey-Event”.

How do you mask things like social insurance, bank-accounts,
European zip-code-country-combinations, etc. ?

Hi Alessandro,

You use the format property for this.

ROCLASI:
Hi Alessandro,

You use the format property for this.

Thank you. So I tried again and lots of new secrets :

Something with Pipe (|) seems to affect the difference in Data Enter and Data Display,
or if I use Stars (*) it seems to control the count of possible typing, even for a variable as
data-provider !

Where can I find a documentation how to use “format”. In the wiki I can’t find any description
about the meaning of Pipe.

Thank you for help.

+1

I find it very strange there is no (complete) formatting options (Wiki) documentation after all these years of Servoy existence.

Maybe not the answer you want, but In the older 3.5 developer, Volume 1 User guides, there are 10 pages spent on string & date format’s.

Paul could you add that to the wiki also? , with all the examples?

you shouldn’t type in directly something in the format property field. (so type the | as the display/edit format separator)
Please use the format editor there, Then you have a legend specifically to the type (string/number/date) what you can use…
And the option to set a edit or display format and so on.
We then generate the right string for you when you fill in that format popup dialog editor.

jcompagner:
you shouldn’t type in directly something in the format property field. (so type the | as the display/edit format separator)
Please use the format editor there, Then you have a legend specifically to the type (string/number/date) what you can use…
And the option to set a edit or display format and so on.
We then generate the right string for you when you fill in that format popup dialog editor.

Thank you, but :?: (maybe I’m to silly …)

1.) I don’t see any “option to set a edit or display format and so on”. In Servoy 6 it looks like this (only display, no edit):
[attachment=0]Print_Screen_01010.jpg[/attachment]

2.) When I enter 3 Stars (*** = anything, but restrict to 3 positions ) it looks during the smartclient-typing like this:
I type only 2 position (for example “a1”) of 3 possible positions, and the rest is displayed as *
[attachment=1]Print_Screen_01011.jpg[/attachment]

3.) When I enter 3 Stars (***) it restrict the User to type more then 3, no mater if the dataprovider is a variable or
not, so the upper discussions: “pure javascript variables (like globals or form) don’t have a length.” seems to be not
true. Isn’t it ?

What I need at the moment is, that the user can type only 3 positions into an empty field (variable as provider) without seeing any " * "
What kind of Format will be the right one ?

Print_Screen_01011.jpg