Birthdate

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Kaubs
Posts: 124
Joined: Wed Jun 29, 2011 3:55 am

Birthdate

Post by Kaubs » Thu Sep 01, 2011 6:33 pm

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

Kaubs
Posts: 124
Joined: Wed Jun 29, 2011 3:55 am

Re: Birthdate

Post by Kaubs » Thu Sep 01, 2011 7:30 pm

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.

jharris
Posts: 84
Joined: Wed Jan 26, 2011 3:28 am

Re: Birthdate

Post by jharris » Thu Sep 01, 2011 7:47 pm

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
Operating System: macOS Monterey Version 12.5
LiveCode Version: 9.6.8

Kaubs
Posts: 124
Joined: Wed Jun 29, 2011 3:55 am

Re: Birthdate

Post by Kaubs » Thu Sep 01, 2011 7:55 pm

Thanks a ton! The keydown message worked a lot better than rawkeyup. It allows for the delete function I couldn't pass lol.

Post Reply