Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How can I verify valid date in Custom Dialog?

Featured Replies

I have script with a Show Custom Dialog allowing the user to change a date. The actual date being changed in the dialog is a global date field, which I will set to the final date field when the date has been validated.

I have already detected if they try to enter nothing - If IsEmpty(gDate), then fail. But I don't know how to detect an invalid date. I tried inserting an If Status(CurrentError) = 500, but it doesn't trigger when it should. Any ideas?

I use global text fields for date entry, because invalid ones are not allowed in global date fields. And if you have Set Error Capture [On], no error message will be returned when an invalid one is entered, but the script will still fail once you attempt to exit the record. Using a global text field makes it easy. You can use If [isValid(TextToDate(gText))] to test the result, without the nasty side-effects. This, of course, means users must enter a 4-digit date, but that should be standard practice already.

  • Author

Excellent suggestion. I am now using the text field and using this validation on it before I proceed with my script:

If [(not IsValid(TextToDate(temp_global_text_4))) or (Length(temp_global_text_4) notequal.gif 10)]

I tested using the two-digit year, but when I tried changing 12/26/2004 to 12/27/04, it actually changed it to 12/27/1904. So, that's why I added the Length(gText) function to catch for that.

I know that FileMaker 6 went through a couple revisions involving the date format, but I know that I have to add that length function on my FileMaker 6.0v4 Dev version.

  • Author

Darn, I just realized that the 10 digit length won't work for dates like 1-1-2005, 1-15-2005 or 10-8-2005. I think this works better:

(not IsValid(TextToDate(temp_global_text_4))) or (Length(RightWords(temp_global_text_4, 1)) notequal.gif 4)

I have another suggestion - not littering a solution with globals:

If [ IsEmpty ( Get ( ScriptParameter ) )  xor  IsEmpty ( Untitled::DateEntry ) ] 

     Perform Script [ "Validate Dialog"; Parameter: Untitled::DateEntry ] 

Else 

     Show Custom Dialog [ Title: "Hola amigo"; Message: "Please enter a new date"; Buttons: "OK"; Input #1: Untitled::DateEntry ] 

     If [  not IsValid ( Untitled::DateEntry ) ] 

          Show Custom Dialog [ Title: "Error!!!"; Message: "Invalid entry...the value is returned to it's previous state"; Buttons: "OK" ] 

          Set Field [ Untitled::DateEntry; Get ( ScriptParameter ) ] 

     End If 

End If 

Where second line is a recursive call!!!

--sd

  • Author

Eh.. what is ScriptParameter? Is that a FileMaker 7 thing?

Oh I appologise, then do you have to use the global JT mentioned - sorry for the inconvenience caused!

--sd

  • Author

Hey no problem - I was half-way through the implementation so I don't think I would have switched to another method anyway.

Actually, I was wrong about the 4-digit year necessity. I also use a script to convert years that may fall under the wrong century.

The only validation that should be necessary is If [not IsValid(TextToDate(temp_global_text_4))] or IsEmpty(temp_global_text_4)] If this validation passes, set your date field with TextToDate(temp_global_text_4) and then If [Year(datefield) < 1990], Set Field [datefield, Date( Month(datefield), Day(datefield), Year(datefield) + 100 )], substituting your lowest year for 1990.

  • Author

Nah... I'd rather force my users to enter 4 digit years. It's a good habit to get into. Plus I wouldn't have to update my script the next century around. wink.gif

What about using a date plugin? That way the date format would always be the same.

A bit costly but it solves the problem of having to code your own date validation routine.

The Mad Jammer

which Plugin???

--sd

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.