12 Replies Latest reply on Aug 17, 2012 3:59 AM by beaconny

    Disable/Enable layout object from script


      Hi, New to FM. Converting application from MS Access for a client. In MS Access it is easy to enable/disable layout object from a script. Cannot find a way to do this in FM.


      Specifically, I have a pop-up menu where user chooses x, y, z. There are 3 related objects on the layout (same table) where a user enters a date for x, y or z. I would like to be able, in a script, to disable the date objects that do not apply and enable the object that applies - the equivalent in the Inspector of unclicking or clicking the Behavior/Field Entry/Browse Mode.


      With Conditional Formatting, I can change the color of the date objects, but want to make them inaccessible.


      Is there a way to do this or is there a work around. Concrete help would be much appreciated. I have 2 books on FM, (FM 12 in Depth and FM Pro 12: the missing manual). Have not found the answer there.

        • 1. Re: Disable/Enable layout object from script

          You can set a global variable when the user selects x, y or z then change the 3 fields to buttons. Create scripts for each button that evaluate the variable and use the go to field script step to place the user in the field.




          • 2. Re: Disable/Enable layout object from script

            Hello, beaconny. Welcome to FileMaker.


            There are at least three methods for doing this.


            1) You can use field validation at the schema level in the Manage Database dialog. Set a calculation on each date field such that, if the proper selection in the pop-up field isn't made, then the field must be empty.


            2) You can set a Script Trigger on the field objects. Run a script that checks the pop-up menu. If the value isn't set appropriately, then alert the user and bounce the cursor to the correct field.


            3) You can use what's called the "hidden portal trick". This involves the use of a self-joining relationship and a pair of fields in the current table. One is a constant calculated field set to, say, "1". The other is a calculation field (usually a global) that evaluates to "1" when the condition is correct. Then, you enclose the object you want to hide in a one-row portal with zero-width lines based on a relationship between the two fields. In this way, the object completely disappears unless the calculated condition is true.


            If you need more explanation on these, let us know.



            • 3. Re: Disable/Enable layout object from script

              Thanks for suggestion. Don't need to take the user to the date field. I merely want to make the date field(s) that are not appropriate inaccessible, but still viewable.

              • 4. Re: Disable/Enable layout object from script

                Thanks for suggestion. Wonderful ideas, except that I don't actually want to hide some of the date fields. I want to make them temporarily inaccessible. Thus want to enable or disable access to them, based on a pick in the popup menu. The user probably won't fill in the date fields right away.

                • 5. Re: Disable/Enable layout object from script

                  Option 1 or 2 leaves the fields visible. Silas's suggestion does as well.



                  • 6. Re: Disable/Enable layout object from script

                    Unless I am missing something, options 1 and 2 do not disable the date field (make it inaccessible). From my reading and playing around in FM, it seems that the only way to disable a field is to uncheck the Browse Mode box on the Inspector Data tab - Behavior - Field Entry. I cannot find a way to do that in a script.


                    In other words, when a user chooses X, Y, Z in a pop-up menu, I would like to enable entry into the correct date field and disable entry into the others --- but still would like all date fields visible.

                    • 7. Re: Disable/Enable layout object from script

                      Use the 'Hidden Tab Control'.


                      For each field make a tab control with two tabs. In tab1 place the normal field. In tab2 place the disabled field. Name the tabs appropiately and use the names in scripts that are triggered by the change of x,y and z checkboxes. The scripts use the script step 'Go to Object'.


                      When everything works as desired, then make the Tab Controls invisible, by making them transparent and no lines. The tab with has to be 0 (zero) to make them unclickable.



                      1 of 1 people found this helpful
                      • 8. Re: Disable/Enable layout object from script

                        Option 2 in Mike's list leaves the field(s) visible AND is able to prevent the user from entering; a script triggered by OnEnterObject can check if a certain condition holds or not, and throw the user out, either by committing the record or going to an “allowed” field. Either way, the user cannot enter the field.


                        Look into the sample file to see how it works.

                        • 9. Re: Disable/Enable layout object from script

                          Thanks. This part now works.

                          • 10. Re: Disable/Enable layout object from script

                            Still have one more problem. Can you look at this script and tell me why the fields are not updating. The tab switching is working well.


                            If condition met in pop-up menu // set 2 date fields, one as blank and the other with the date 1/1/2001


                            Set Field By Name [CustomerDetail::ConfirmPickupSchedule]; Date ( 1 ; 1 ; 2001 )

                            Set Field By Name [CustomerDetail::ConfirmShippingSchedule]; GetAsDate ("")


                            • 11. Re: Disable/Enable layout object from script

                              “Set Field by Name” sets the field whose name is contained in the field you're referencing; what you want is plain old “Set Field”.


                              I suggest you use the other method. Since you're employing a script anyway, this relieves you of fiddling around with an invisible tab object; also, should you want to prevent entry into other fields at a later point, you have to either put all those fields adjacent or make more tab objects.

                              • 12. Re: Disable/Enable layout object from script

                                Would like to thank everyone for their helpful answers. I am learning alot. What a wonderful site this is. Hopefully someday I will know enough to contribute to other new users.