1 2 Previous Next 15 Replies Latest reply on Jan 6, 2012 3:23 PM by comment

    Toggling Checkboxes On and Off

    bnation83

      I have a check list/observation form that runs in FM Go on an iPad. Due to the number of items on the form and that the end user want's it to look as close to the paper form as possible the check boxes are somewhat small. So I am attempting to write a script for a button that that will toggle on/off each check boxes. The "check boxes" are boolean with a value list of "1". I don't what to have a super long script with a case statement for each checked item/field. I'm passing the file name via a variable and also passing each check box name (the actual field name) via the Get (ScriptParameter). Both seem to be getting passed correctly. Because of this I need to use the Set Field By Name function. When I use run a version of the script using the actual field names and the Set Field the toggling works. When I put the variables back in it only toggles one way depending on if my IF statement is "not isEmpty(field)" or "isEmpty (field)". I have tried using global variables ($$) or local variables ($).

       

      Here's the script.

      Set Variable [ $FileName; Value:Get [ActiveFieldTableName) & "::"]

       

      Set Variable [$CheckBox; Value:Get(ScriptParameter)]

      if [not IsEmpty ($FileName & $CheckBox )]

      Set Field By Name [$FileName & $CheckBox; ""]

      Else

      Set Field By Name [$FileName & $CheckBox; 1]

      End If

       

      Any suggestions would be greatly appreciated.

      Brad

        • 1. Re: Toggling Checkboxes On and Off
          taylorsharpe

          Try the Evaluate Function. 

           

          Set Variable [ $FileName; Value:Get [ActiveFieldTableName) & "::"]

          Set Variable [$CheckBox; Value:Get(ScriptParameter)]

          if [not IsEmpty ( Evalutate ( $FileName & $CheckBox ) )]

             Set Field By Name [$FileName & $CheckBox; ""]

          Else

                Set Field By Name [$FileName & $CheckBox; 1]

          End If

          • 2. Re: Toggling Checkboxes On and Off
            Bobster

            Hi Brad,

             

            The part I've quoted below is all fine, but your script is longer and more complicated than necessary.

             

            Simply create a button with no borders and no fill. Place it over your checkbox field. Make it "fingertip size" for the iPad.

             

            Assign the following Set Field action to each button:

             

            not myFile::myField.

             

            Whatever state the boolean field is in (including, at first, Empty) the button action will set it to the opposite.

             

            i.e. "1" becomes "0".  Empty, or "0" becomes "1".

             

            HTH,

             

            Bob.

             

            Bob Stuart

            Lord Of The Files

            Think Data Pty Ltd

            Noosa

            Queensland

            Australia.

             

            +61 7 5442 5624

            +61 413 350 993

            • 3. Re: Toggling Checkboxes On and Off
              taylorsharpe

              The single step way of doing is is to:

               

               

              Set Field By Name [ Get ( ActiveFieldTableName ) & "::" & Get ( ScriptParameter )  ;  If ( IsEmpty ( Evaluate ( Get ( ActiveFieldTableName ) & "::" & Get ( ScriptParameter ) ) ) ; 1 ; "" ) ]

               

               

              But it might not be as intuitive as your original script. 

              • 4. Re: Toggling Checkboxes On and Off
                Tom_Droz

                Brad

                I use lots of forms with check boxes. I have the box with a conditional format.  If the underlying data is in the field it shows an "X" if is not there it shows a white "X" set at 500 Pt size (so it is effectively invisible).

                 

                The box itself has a script which sets the field. Similar to above, if the data is already there it removes it, if the data is not there it adds it.

                Tom

                • 5. Re: Toggling Checkboxes On and Off
                  BruceHerbach

                  Brad,

                   

                  You might consider setting up the button to send the whole field name by using the getfieldname() function.  Then get(scriptparameter) would get the tablename and the fieldname.  The other advantage to this is that if you ever rename the field,  the script and buttons will still function.

                   

                  Your script could be

                  set field by name[ get(scriptparameter) ; if(getfield(getscriptparameter);0;1)  ]

                   

                  Please not that this assumes you are using version 10 or 11.  Version 9 doesn't have the getfieldname function.

                  Hope this helps

                  Bruce Herbach

                  • 6. Re: Toggling Checkboxes On and Off

                    Hi Brad,

                     

                    The problem with Get ( ActiveFieldTableName) is that, even if entry is allowed to the field, a script will fire before evaluating it.  You can test it by putting it in the script parameter and then script with only

                     

                    Show Custom Dialog [ Get ( ScriptParameter ) ]

                     

                    It will work if using script trigger OnObjectEnter. However, since the User can enter the field (the only way it will properly evaluate Get ( ActiveFieldTableName ) then it means the User can enter the checkbox itself and change the value (which will negate (reverse) the script’s action).

                     

                    I would suggest this approach:  Use transparent rectangle over the field or attach directly to the field (disallow entry to the field).  Script parameter would be:

                     

                    GetFieldName ( Evaluate ( "yourFieldinQuotes" ) )

                     

                    Script would be:

                     

                    Set Field By Name [ Get ( ScriptParameter ) ; Substitute ( not Evaluate ( Get ( ScriptParameter ) ) ; 0 ; "" ) ]

                     

                    This will produce 1 or blank and the only thing you must hard-code is the field name (portion in bold). 

                     

                    I removed the suggestion of exiting the checkbox field because, since I suggest script, the field is not entered anyway so it does not need to be exited.

                     

                    Message was edited by: LaRetta

                    • 7. Re: Toggling Checkboxes On and Off
                      bnation83

                      Thanks for all the assistance.  It's now working.

                      Brad

                      • 8. Re: Toggling Checkboxes On and Off
                        bnation83

                        Thanks a bunch!

                        • 9. Re: Toggling Checkboxes On and Off
                          Bobster

                          So, Brad, what approach did you take?

                          • 10. Re: Toggling Checkboxes On and Off
                            bnation83

                            I used the suggestion from LaRetta:

                            I would suggest this approach:  Use transparent rectangle over the field or attach directly to the field (disallow entry to the field).  Script parameter would be:

                             

                            GetFieldName ( Evaluate ( "yourFieldinQuotes" ) )

                             

                            Script would be:

                             

                            Set Field By Name [ Get ( ScriptParameter ) ; Substitute ( not Evaluate ( Get ( ScriptParameter ) ) ; 0 ; "" ) ]

                             

                            This will produce 1 or blank and the only thing you must hard-code is the field name (portion in bold).

                             

                            • 11. Re: Toggling Checkboxes On and Off
                              Bobster

                              Hi Brad,

                               

                              I must have misunderstood what you're trying to achieve. How is

                               

                              Set Field By Name [ Get ( ScriptParameter ) ; Substitute ( not Evaluate ( Get ( ScriptParameter ) ) ; 0 ; "" ) ]

                               

                              superior to the simple

                               

                              Set Field not myFile::myField

                               

                              ?

                               

                              Have I missed something?

                               

                              Regards,

                               

                              Bob

                              • 12. Re: Toggling Checkboxes On and Off
                                bnation83

                                I tried the one I ended up using  before I even gave your's a try.  At that point it worked and I had had enough trying to get it working. I suppose that when I get the time I will give your's a try.

                                 

                                Brad

                                • 13. Re: Toggling Checkboxes On and Off
                                  comment

                                  bnation83 wrote:

                                   

                                  I am attempting to write a script for a button that that will toggle on/off each check boxes.  ...  I don't what to have a super long script with a case statement for each checked item/field.  I'm passing ... (the actual field name) via the Get (ScriptParameter). ...  Because of this I need to use the Set Field By Name function. 

                                   

                                  IMHO, it would be much simpler to define each button to set a field directly - without a script.

                                   

                                   

                                   

                                  If you prefer to do it by a common script, then make your parameter =

                                   

                                  GetFieldName ( YourTable::YourField )

                                   

                                  and the script:

                                   

                                  Set Field By Name [ Get ( ScriptParameter ) ; not GetField ( Get ( ScriptParameter ) ) ]

                                   

                                   

                                  There is no need to pass the file name to the script, or to hardcode any field names into the script or the parameter.

                                  • 14. Re: Toggling Checkboxes On and Off

                                    Hi Comment,

                                     

                                    You still need to place the field name within the script parameter somehow ... either by selecting it from pop-up or by typing it.   It would be easier to select from the pop-up and that would eliminate issue of script breaking if field name changes - I just followed the flow of hard-coding the field name and didn't catch it.  Anyway, that is why I evaluated in both cases ... if the field name is text then it would only work with evaluation, LOL.  Also, the request was for 1 or blank and not Boolean 1 or 0 which is why I added the Substitute() at the last minute.  Your solution still produces 1/0.

                                     

                                    Thank you for stepping up - your approach is better and I hope Brad changes you to the correct answer!!  

                                     

                                    LaRetta

                                    1 2 Previous Next