Page 1 of 1

Birthdate

Posted: Thu Sep 01, 2011 6:33 pm
by Kaubs
I am trying to create a dynamic birthdate field in my app. I have a field the user can enter data into but in my testing I am doing something terribly wrong. I'd love to make the date look like 09/01/2011 when the user types in the field 09012011. I started testing by adding a / after the first two chars entered. However it just keeps putting / in always. Any ideas on what I'm doing wrong? Thanks!!!!
on rawkeyup
put numtochar(47) after char 2 of field "field"
end rawkeyup

Re: Birthdate

Posted: Thu Sep 01, 2011 7:30 pm
by Kaubs

Code: Select all

on rawkeyup
   put the number of chars of field "field" into fieldnum
   if fieldnum = 2 then
      put numtochar(47) after char 2 of fld "field"
      else if fieldnum = 5 then
         put numtochar(47) after char 5 of fld "field"
      end if
end rawkeyup
Will put the / in where I like them but since I have no handler for del it just keep adding them if you try to remove chars.

Re: Birthdate

Posted: Thu Sep 01, 2011 7:47 pm
by jharris
Hi Kaubs,

I don't know if this is the best way (probably not), but it is what I have been using.

In the field script try:

Code: Select all

on keyDown keyName
     local tText
     -- Code to format the text as a date
     if (keyName is a number) and (the length of me < 10) then
          if the length of me = 2 then
               put "/" into the selection
          end if
          if the length of me = 5 then
               put "/" into the selection
          end if
          pass keyDown
     end if
end keyDown
regards,
jharris

Re: Birthdate

Posted: Thu Sep 01, 2011 7:55 pm
by Kaubs
Thanks a ton! The keydown message worked a lot better than rawkeyup. It allows for the delete function I couldn't pass lol.