Validating decimal cells in tables?

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Validating decimal cells in tables?

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:10 pm

by JADE News Administrator >> Thu, 29 Oct 1998 2:40:46 GMT

Hi
I have some tables set up for input and I want to be able to validate a column setup for input of a currency figure.

The input types available for table cells allow String, Combo box, Integer etc -- but strangely not Decimal.

And using Integer doesn't allow for entry of the decimal point. Hence I have to use String.

How can I easily validate such a column when the user leaves the cell to ensure a valid currency figure has been entered ?


Ciao .................
Alan J.Thomson
ph...Auckland 09-277-7961 x 744
http://home.clear.net.nz/pages/athomson

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Validating decimal cells in tables?

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:10 pm

by JADE News Administrator >> Thu, 29 Oct 1998 2:41:34 GMT

Alan,

I've come across the same thing (I raised a fault about the decimal not being enterable for numeric-only input, but was told that it's "working as intended" !).

Anyway, I got around this by putting a method on the string primitive (String::isNumeric), which does the following:

isNumeric():Boolean;

vars
position : Integer;
length : Integer;
char : Character;
begin

length := self.length;
position := 1;

while (position <= length) do
char := self[position:1].Character;

if (not char.isNumeric) and (not char = ".") then
return false;
endif;

position.inc(1);
endwhile;

return true;
end;

Note that the "inc(1)" method of the "position" integer is a method I
put on the Integer primitive to increment the variable by the specified value.
--
Darrell Duniam
dduniam@cardinal.co.nz
www.cardinal.co.nz

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Validating decimal cells in tables?

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:10 pm

by JADE News Administrator >> Thu, 29 Oct 1998 3:11:30 GMT

Yes, as noted elsewhere -- I found that if I took my table entry and assigned it to a temporary String variable and just did a check on the isDecimal boolean property then this worked fine for identifying if the string entry was an integer or a decimal

cheeriby
Alan____________

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Validating decimal cells in tables?

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:10 pm

by Darrell Duniam >> Fri, 30 Oct 1998 22:39:52 GMT

If you put a method on the string primitive, you wouldn't have to bother assigning the cell text to a variable and then validating that, you'd simply need:

if (not table1.getCellText(row, col).isNumeric) then
.... error stuff
endif;

--
Darrell Duniam
dduniam@cardinal.co.nz
www.cardinal.co.nz

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Validating decimal cells in tables?

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:10 pm

by Allistar Melville >> Tue, 10 Nov 1998 13:03:18 GMT

The way I used to get around this problem is by making the cell type InputType_TextBox and trapping the keyDown method (or was it keyPress?
I can't remember now). Essentially in the keyDown/press event on the table you say that if you are in a decimal cell, only let the keys [1,2,3,4,5,6,7,8,9,0,-] through. This means that there is no way the
user can input an invalid decimal amount. This works well.

Allistar.

------------------------------------------------------------------
Allistar Melville (BSc) Home: allistar@ihug.co.nz \_
Software Developer Work: allistar@focussoft.co.nz </'
Auckland, NEW ZEALAND /)
Web: http://homepages.ihug.co.nz/~allistar/ (/`
`
"A wise man proportions his belief to the evidence." David Hume ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Validating decimal cells in tables?

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:10 pm

by Bill Thomas >> Wed, 11 Nov 1998 23:48:56 GMT

Greetings,

The only problem I see with using keyDown/keyPress in the way described is that
it is only validating the individual keystrokes, not the value as a whole. E.g.
000-9 is not a valid number but would pass the test, checking character by character. Using the Jade built in isDecimal method on the entire entered string
would appear to be the best way as it handles decimal fractions as well as whole
numbers. That would leave the question of whether you do the isDecimal test every time a key stroke is entered into the cell or only when you are ready to
update the database. I have sometimes used the technique where the data entered into a cell is checked only when another cell is selected or the table control loses the focus. This means the user can type any rubbish they like
into a cell but will get pulled up if they try to move to another cell or control.

Cheers Bill

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Validating decimal cells in tables?

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:10 pm

by Allistar Melville >> Wed, 11 Nov 1998 16:32:10 GMT

Not at all. You just have to be clever in how you code the
keyPress/Down method. (e.g "-" is only valid as a first character, "."
is only allowed once etc). This way means that the overhead happens
when the user strikes the key, and the overhead is very small (a few
if statements should do it).

I think that preventing the user from entering invalid data is by far
the best policy.
Using the Jade built in isDecimal method on the entire entered string
would appear to be the best way as it handles decimal fractions as well as whole
numbers. That would leave the question of whether you do the isDecimal test every time a key stroke is entered into the cell or only when you are ready to
update the database.

Doing it on every keystroke seems like a bit of an overkill (although admittedly the isDecimal() test wouldn't slow it down much, if any).
I have sometimes used the technique where the data entered into a cell is checked only when another cell is selected or the table control loses the focus. This means the user can type any rubbish they like
into a cell but will get pulled up if they try to move to another cell or control.

We use this technique also (not for decimal validation, though). If
the user is in a decimal cell and they enter "23", when they move out
of that cell it's contents becomes "23.00", which makes everything
look nice :-p.

We have noticed that jade gives you no way of selecting the contents
of a cell when you move into it (which makes fast data entry into a
table a real pain as the user has to delete the contents of the cell
out first).

Our way of combatting this was to subclass the Table control and reimplement the way input types are handled. Essentially we don't let Jade control the InputType_TextBox cells as we actually place a text
box control on the cell instead. As far as the user is concerned
nothing has changed, but we now have nice features like selecting the contents of the cell when you move into it (this is also the way we
got around the above decimal validation problem).

Allistar.

------------------------------------------------------------------
Allistar Melville (BSc) Home: allistar@ihug.co.nz \_
Software Developer Work: allistar@focussoft.co.nz </'
Auckland, NEW ZEALAND /)
Web: http://homepages.ihug.co.nz/~allistar/ (/`
`
"A wise man proportions his belief to the evidence." David Hume ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Validating decimal cells in tables?

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:10 pm

by Craig Shearer >> Thu, 5 Nov 1998 23:50:05 GMT

I vote for a new JADE feature to allow selection of an input cell in a table control - preferably with some sort of "gotFocus" and "lostFocus" events too.

Craig.


Return to “Tips and Techniques”

Who is online

Users browsing this forum: Bing [Bot] and 11 guests

cron