how to check field format during entry

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
fmuller
Posts: 11
Joined: Mon Mar 08, 2010 1:02 pm

how to check field format during entry

Post by fmuller » Sat Apr 10, 2010 8:51 pm

Hello,

I search if something exist to check what is entered inside a field on screen like a format template.
For some fields I would like just numbers, others just characters and so ...
Some languages have input values like "####" means only 4 numbers or "##/##/####" means a date.

Thanks for help,
Cheers, Fabrice
Last edited by fmuller on Sun Apr 11, 2010 8:36 pm, edited 1 time in total.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: how to check field format during entry

Post by Klaus » Sun Apr 11, 2010 4:36 pm

Grüezi Fabrice,

ca va bein? :)
fmuller wrote:...For some fields I would like just numbers, others just characters and so ...
This is quite straighforward!

Put this into the fields script to allow only numbers as input including prefix -+ and decimal delimiter which is comma in my example!

Code: Select all

## We check the typed character BEFORE we put them into the field!
on keydown tKEy
  if tKey is in "1234567890,-+" then

   ## Typed character OK, let it pass
     pass keydown
  end if
end keydown
Same for non numeric input:
... if tKey is in "abcdefghijklmnopq..." ### etc...
Hint: "A = a" if you do not "set the wholematches to true" before you compare something!
fmuller wrote:Some languages have input values like "####" means only 4 numbers or "##/##/####" means a date.
THis is not built in into Rev unfortunately.
But you can check the field after the input and format the content accordingly.
Use the "closefield" handler to do so and maybe the "format" function.
Example: User entered a number (1) but we woul like to see the field formatted like 1.00:
Hint: the engine always uses english decimal formatting 1.00, so here in my scripts in germany I do:
...
replace "." with "," in tnumber
...
Before I put the string back into the field.

Code: Select all

on closefield
  put me into tnumber
  put format("%1.2f",tnumber) into me
end closefield
Of course there is a lot of errochecking needed, like empty fields etc...

Hope that helsps!


Best from germany

Klaus

fmuller
Posts: 11
Joined: Mon Mar 08, 2010 1:02 pm

Re: how to check field format during entry

Post by fmuller » Sun Apr 11, 2010 8:55 pm

Hi Klaus,

Alles gut und dich, hast du ein schönes Wochenende gehabt ?

I switch to English, it's easier :-) Thanks a lot for your solution I will try it.

Cheers from Switzerland, Fabrice

FLCo
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 36
Joined: Thu Jul 27, 2006 5:40 am
Contact:

Re: how to check field format during entry

Post by FLCo » Sat Dec 14, 2013 1:35 pm

FieldFormatter is now available...

http://www.FlexibleLearning.com/fieldformatter

It does exactly what you are asking for.

Hugh Senior
The Flexible Learning Company
• ChartMaker: www.FlexibleLearning.com/chartmaker
• ControlManager: www.FlexibleLearning.com/controlmanager
• The Scripter's Scrapbook: www.FlexibleLearning.com/ssbk
• DatePicker: www.FlexibleLearning.com/datepicker

Post Reply