10 Replies Latest reply on Jan 24, 2014 1:50 PM by john.s

    Help with validating Time Format



      Help with validating Time Format



           I using global variables in a layout that will later create new records and print a verification report.  The global var for the time of a session is set up as a Type:Time with Validation Strict data type: Time of Day.  When something that is not a time is entered an error message pops up as soon as another field is clicked.  The problem comes when the time field is the last field entered before hitting the button that runs a script to verify certain fields are not empty, save the current changes, create new records and print a report.  When that happens a pop up asking if you want to Save the record comes up four times.  Is here a was of making sure the time entered is in a format hh:mm (I don't care about AM or PM and it doesn't actually have to be a time field, text would work) without all the extra pop ups?

        • 1. Re: Help with validating Time Format

               That message should not pop up 4 times. Other than the validation error message, is the record save confirmation dialog the only other message that appears?

               Do you have auto-save turned off for this layout? Do you want that?

               Does your script have commit records steps in it?

               You could set an OnObjectValidate trigger on the field and then create your own script to validate data in the field.

          • 2. Re: Help with validating Time Format

                 Hi Phil,

                 Auto-save is turned off for this layout.  I want to control when the record gets saved and think I am doing that in the attached script.  It seems to work as planned except for the time field.

            • 3. Re: Help with validating Time Format

                   In looking at the data it appears that if just a 1 is entered into the time field the system sees that as a time of 01:00:00 and my script step test passes and the script continues with all of the commit record steps which must be prompting the save confirmation.  I just don't know how to fix it.

              • 4. Re: Help with validating Time Format

                     Yes. Entering 1 into a time field will be interpreted as entering a time of 1 am. FileMaker will not interpret that as an invalid time with the settings you have given.

                     But it's very easy to commit records from a layout even when it has been set to disable the auto-save. Just clicking the layout back ground will commit records and cause the "do you want to save?" dialog to appear.

                     What seems very unusual is to get this dialog 4 times. As far as I can tell, this will not come from the script you've posted as it commits with the "no dialog" option specified.

                     Try this test:

                     Enter an invalid time and click the layout background. This should both pop up a validation error message and try to commit records. Do you get the same results as when you click your button to save the record?

                     I think that you will need an additional script performed from an OnObjectValidate trigger set on your time field in order to get the results that you want. That script can validate the data in your time field before the validation field options set on the field can kick in. An Exist Script [False] step can then cancel out the field exit and return the focus and the user to the time field to correct invalid entries. (And if you don't want to except simple numbers from 1 to 24 as time input, your script can detect and react to those data entry issues as well.)

                • 5. Re: Help with validating Time Format

                       I have set one large invisible (Do Nothing) Button on the layout behind all the input fields to prevent committing the record so I can do it with the script.  So when I enter something invalid like an A in the time field nothing happens unless I click in another field and then I get the invalid time message.

                       I'm updating this as I test. So I just made a copy of the layout and deleted the big do nothing button.  When I enter an invalid time I get the error and an option to revert when I click on the background.   And as I mentioned earlier if I run the script it goes crazy.   I'll try your suggestion of adding an OnObjectValidate trigger and write another script to validate the input and we'll see what happens.

                  • 6. Re: Help with validating Time Format

                         OK, so once again I'm lost.  I have decided to make the SessionTime a text field, I don't care about AM & PM and do not need to do any time calc with this field.  Now I can test in the main script for a few things.  First I check to see that the length is either 4 or 5.  If it is 4 I want to be sure there is a colon : in the second position and if the length is 5 their should be a : in the third position.  Any help will be greatly appreciated.

                    • 7. Re: Help with validating Time Format

                           That sounds like checks that you could build into your existing "Save" script. If it proves a valid entry, part of the save could be to then enter this data into an actual time field:

                           Set FIeld [ YourTable::TimeFIeld ; GetAstime ( YOurTable::TextTimeField ) ]

                      • 8. Re: Help with validating Time Format

                             I didn't think of that…I'm testing the global field and it makes sense to then enter it into a time field.  What I need help with now is determining if it is in the correct format.  How do I test to see if there is a : in the third position from the right.  I've tried the Right function and PatternCount but can't figure this out.

                        • 9. Re: Help with validating Time Format

                               Use the Position function to check for both the presence of and the position of the colon.

                          • 10. Re: Help with validating Time Format

                                 Thanks again Phil…it is now working as planned.  I learn something new every day