Editing a numeric field

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
warrenk
Posts: 110
Joined: Sun Sep 21, 2008 5:39 am

Editing a numeric field

Post by warrenk » Tue Mar 17, 2009 7:12 pm

I have a numeric field which I limited the size to 7 digits:

on keyDown theKey
if theKey is a number and the length of me <7 then
pass keyDown
end if
end keyDown

When I put 7 digits in the field and tab back into the field, I try to enter a new number and it doesn't allow me. My key strokes don't work until I delete the value first.

I have used the command:
select the text of field "Quantity Ordered"
...which selects the whole field. Shouldn't the value get overwritten when the field is selected and I key a new value?

Hopefully I explained myself clearly. :)


Thanks for any help!
Warren

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Tue Mar 17, 2009 7:58 pm

Upon keyDown the insertion hasn't happened yet. You could check the selectedChunk to see if anything in the field is selected.

Code: Select all

on keyDown pKey
  local tOkeyFlag, tSelectionStart, tSelectionEnd
  put false into tOkayFlag
  if pKey is a number then
    put word 2 of the selectedChunk into tSelectionStart
    put word 4 of the selectedChunk into tSelectionEnd
    if tSelectionEnd > tSelectionStart or length(the text of me) < 7 then
      put true into tOkayFlag
    end if
  end if
  if tOkayFlag is true then
    pass keyDown
  else
    beep
  end if
end keyDown
HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

warrenk
Posts: 110
Joined: Sun Sep 21, 2008 5:39 am

Post by warrenk » Thu Mar 19, 2009 1:55 pm

Jan,

Thanks again!!!! This solution worked perfectly.

Warren

Post Reply