3 Replies Latest reply on Feb 19, 2014 9:59 AM by philmodjunk

    Checkbox Scripting

    WilliamSommerville

      Title

      Checkbox Scripting

      Post

           Hi all, greatly appreciate the forum.

           I am new to FMP and so far so good.

           I need to script a checkbox like a switch. So for example I have checkbox1 and checkbox2.

           If checkbox1 = on then

           checkbox2 = off

           elseif checkbox2 = on

           checkbox1 = off

           endif

           This way it can only be one or the other and not both when click. Is there a script example that covers this?

           Thanks

            

            

        • 1. Re: Checkbox Scripting
          TSGal

               William Sommerville:

               Thank you for your post.

               If you are new to FileMaker Pro, I would first consider changing the formatting of the field to a radio button, as this only allows one entry.  That is, you can only select one value.  If one value is selected, the second value is unselected, and vice versa.

               If the checkbox values are in separate fields, you could use a script trigger for both fields.  For "Checkbox 1", the script would read:

               Set Field [ Checkbox 2 ; If ( IsEmpty ( Checkbox 1 ) ; <Checkbox 2 desired value> ; "" ) ]

               In essence, this looks at the value of "Checkbox 1".  If it is empty, then assign the value of "Checkbox 2".  Otherwise, delete the entry in "Checkbox 2".

               You will need a second script that will be used for "Checkbox 2", but specifying "Checkbox 1".  That would be:

               Set Field [ Checkbox 1 ; If ( IsEmpty ( Checkbox 2 ) ; <Checkbox 1 desired value> ; "" ]

               Next, go to Layout Mode, click once on the field "Checkbox 1", pull down the Format menu and select "Script Triggers...".  Enter a checkmark next to OnObjectModify, and when prompted for a script, select the script associated with "Checkbox 1".  Click OK.  Do the same for the "Checkbox 2".

               Go to Browse Mode, and enter a checkmark into Checkbox 1.  Notice there is no value in Checkbox 2.  Uncheck Checkbox 1, and the value in Checkbox 2 is selected.

               Let me know if you need additional clarification.

               TSGal
               FileMaker, Inc.

          • 2. Re: Checkbox Scripting
            danshockley

                 One caveat to add to TSGal's explanation of how you can handle this: radio buttons are a great way to visually tell the user that they should only select one of two or more choices. However, it does not ensure data integrity. It is possible to select multiple values or even enter data not in the value list by using copy/paste or dragging text into the field. If you need to validate the integrity of the data, use the Validation section of the field definitions. 

                 With radio buttons, you can select more than one by shift-clicking. You can paste anything in by clicking into the field and then pasting. You can drag arbitrary text into a field that has radio buttons if FileMaker's preference for "drag and drop text selection" is turned on. 

                 The same is true for popup menus and checkboxes, which at first glance seem to allow only specific choices. 

                 Moral of the story: those data entry controls are to help build useful interfaces and suggest what data the user should pick. They are not designed to ensure data integrity. 

            • 3. Re: Checkbox Scripting
              philmodjunk

                   I would use an auto-enter calculation to reject "dropped" text and to reject selecting a second value via holding down the shift key. But this is the FM GO forum so if you are doing this in FM GO, these kinds of "end runs" around the interface will be harder to do. (Have to test to see if it is even possible in FM GO.)