4 Replies Latest reply on Feb 5, 2015 9:30 PM by paolobkk

    Validation of data in custom dialog to accept only one single number - script

    paolobkk

      Title

      Validation of data in custom dialog to accept only one single number - script

      Post

      I have an input system in FMP11 that uses a dialog box with a global field to input quantities for each record. On click OK the script will add the value in the record proper field.

      The users should enter just one number in that dialog box global field (e.g.: "10" or "-10").

      I'm trying to create a validation script to make sure that the users don't type weird stuff except that one number.

      (It happened that they typed expressions and spaces, making the system fail. e.g.: "+10-5+ 30- 15" ).

      So far I got to his:

      Once typed the value in the Custom dialog  GLOBALFIELD and click OK ->

      If [(Lenght ( Filter ( Lower ( GLOBALFIELD ) ; "1234567890-" ) )) = ( Lenght ( GLOBALFIELD) )) ) and ( Patterncount ( GLOBALFIELD ; "-" ) ≤ 1 )]

      Set Field ( RECORDFIELD ; RECORDFIELD + GLOBALFIELD)

      Else

      Error message and Exit Script

      End If

      On my tests everything looks fine but I would appreciate any comment from an external eye.

      Thank you all for your help.

      Have a great day.

        • 1. Re: Validation of data in custom dialog to accept only one single number - script
          philmodjunk

          Instead of show custom dialog use New window and select a layout designed for use as a global field, This can allow you better options for controlling input in that field--such as an OnObjectKeystroke trigger that disables certain keys such as the + and space keys from being able to input characters into the field. This can even be done to limit the - operator to only being accepted as the first character in the field so that negative values can be entered but not 5 - 5.

          This layout could also use a portal to a related table for collecting data to make it easier for your users to enter multiple values while your dialog is open for accepting input.

          • 2. Re: Validation of data in custom dialog to accept only one single number - script
            paolobkk

            Hi Phil, Thank you for your reply.

            I forgot to mention that we are using FMP11 and the new window may get forgotten open and create confusion.

            In fact I use already dialog windows in other solutions on FMP12.

            I need the custom dialog because the user need to keep the primary window in background for quick check data while typing. But cannot access the primary window until submit the data in the dialog box.

            • 3. Re: Validation of data in custom dialog to accept only one single number - script
              philmodjunk

              It's important to tell people what version you are using when it's not the latest version. Otherwise, people can waste time posting a suggestion that you cannot use with your older version.

              But I kept such windows open in FileMaker 11 in a modal state all the time. It was a bit of a kludge, but it worked. (Note: in FileMaker 13, you not only have modal windows, you can use a popover instead of the window and this is often a nicer option.)

              Here's how to script the creation of a pseudoModal dialog in FileMaker 11 or older with the New Window script step:

              Allow User Abort [off] --. only add this after thorough testing as this can trap you in a state where you have to force quit
              New Window
              Go to Layout
              Show/Hide Tool Bars [Hide]
              Adjust Window [resize to fit]
              Loop
                 Pause/Resume Script [indefinitely]
              End Loop

              You put buttons on the layout used with this window that perform a script to close the window. Specify either the "Halt script" option on the button or include a Halt Script step at the end of the script. This step will interrupt what is otherwise an endless and uninterruptible infinite loop that traps the window into a modal state. If you have FileMaker Advanced, you can install a custom menu that performs a script to close the window and halt the paused script in place of the standard Close Window menu option. This can enable the close window control in the corner of your pseudomodal dialog window.

              • 4. Re: Validation of data in custom dialog to accept only one single number - script
                paolobkk

                Hi Phil, Thank you for your patience and explanations.

                Creating a new dialog layout in a new window as you described would include a bit too much time and effort as the system and the scripts involved are already pretty complex. However I'll keep in mind how you created the pseudoModal dialog window, which I can use in future development.

                After consulting with other developers I've managed to solve the problem by adding a simple script step to validate the data typed by the user before continue the script:

                Filter ( GLOBALFIELD ; "1234567890-" ) = GLOBALFIELD
                and
                Patterncount ( GLOBALFIELD ; "-" )  1
                and
                Position ( GLOBALFIELD ; "-" ; 1 ; 1 )  1

                If validation fails, the script will return an error message and exit script.