7 Replies Latest reply on May 25, 2011 8:22 AM by philmodjunk

    Disabling/Changing Field Behavior Using Scripts

    JustinLevens

      Title

      Disabling/Changing Field Behavior Using Scripts

      Post

      Is there a way change the field behavior or gray out fields using scripts?  What I'm trying to do is have fields disabled but viewable on the screen unless a radio button is selected as "Yes", then the fields become active and editable.  It doesn't look like conditional formatting will work for graying out since it seems conditional formatting on applies to that specific field and I can't find a way to edit field properties via scripts.

        • 1. Re: Disabling/Changing Field Behavior Using Scripts
          philmodjunk

          If you have multiple fields where you need this option, you may want to consider defining those fields in a separate record related with a one to one relationship to your current record. Then, You can use Manage | Security to controll access to those fields via a "lock expression".

          See "Editing record access privileges" in FileMaker Help and check out this particular sub section: "Entering a formula for limiting access on a record-by-record basis" for a detailed description of how to set this up.

          With conditional formatting, you can change the appearance of a group of fields by giving them all the same conditional format expression that checks the value of another field or a variable. Your button can change the value of this variable or field to trigger the format change. This is just cosmetic, it won't, by itself, control behavior.

          You can also set validation calculations that reject any edits made to the field if your Lock field or variable is set to the "locked" value. This allows access to the field, but when validation kicks in, all changes are rejected and the user has to revert the field.

          You can also use OnObjectEnter script triggers to control access to the field by running a script that checks your lock field/variable and uses go to field or go to object to move the cursor back out of the field if access is not permitted.

          • 2. Re: Disabling/Changing Field Behavior Using Scripts
            rjlevesque

            Good Day Justin,

            You could make two layouts, identical in every way except have static, not editable, fields on one layout. Then make your script switch to the open field layout upon selection of the radio button.

            Can you tell me a little more about what you are trying to accomplish? Just elaborate a little more for me, why graying fields, what's the general function of the layout?

            • 3. Re: Disabling/Changing Field Behavior Using Scripts
              rjlevesque

              And I was just about to say you can also use Triggers, but I see Phil already mentioned that. Cool

              • 4. Re: Disabling/Changing Field Behavior Using Scripts
                philmodjunk

                Yes, and the dual layout approach (once upon a time the only real option many versions ago ) is worth considering. It's not as secure as it requires care on the part of the developer to make sure there are no "loop holes" and that the wrong layout is never presented, but it's also pretty simple to set up.

                • 5. Re: Disabling/Changing Field Behavior Using Scripts
                  JustinLevens

                  I think having dual layouts will best serve my purpose.  It's mainly just for cosmetic purposes.  The layout will be used to schedule doctor appointments and one of the appointments is optional/not alway required.  So by default I want the fields grayed out and if the scheduler selects "Yes" to the appointment being required, the fields are activated.  I don't necessary need the fields locked.  The appointments section is in a portal, so I'll likely just need to make sure the correct records are showing.

                  Thanks for the help.

                  • 6. Re: Disabling/Changing Field Behavior Using Scripts
                    JeanDENOEL_1

                    Hi.

                    Justin's question is about the same as the one I wanted to ask. But his purpose is not exactly the same as mine.

                    I also would like to alter the record access privilege in time. My problem is that I don't want to be able change the content of a field by mistake. I would like to have all the fields of a record viewed on a layout to be uneditable unless I definitely decide to change one or all of them (with an "Edit" button for example).

                    I could, as mentioned here above, create 2 fully identical layouts (except for the behavior of the fields - editable or not editable) perfectly on top of each other and switch between those two depending on the value of a global variable I could control with a button. But from the discussion Justin initiated, I understand that this is not the most elegant and most secure solution. Am I right?

                    And even if this is acceptable, how can I switch from on layout to the other if all these fields I want to protect are displayed on Tab panel of a more general layout?

                    Screen capture
                    Hope you can make this a little clearer for me.
                    Thanks
                    Jean

                    • 7. Re: Disabling/Changing Field Behavior Using Scripts
                      philmodjunk

                      For what Justin describes in his last post, he does not even need two layouts, just conditional formatting set up so that a script can control what format is displayed.

                      If you review the thread, you'll see that my initial recomendation was to use Manage | Security to control access to your fields. This requires performing "surgery" on your table to split it into two related records if you want to limit access to some fields, and not others, but it is the most secure way to control access in this fashion. I also briefly mention that you can use OnObjectEnter to run a script that moves the cursor back out of the field if the lock status is enabled for the current record.

                      Switching layouts is not nearly so secure--there are several easy ways to pull up a records with 'locked' fields on the layout that leaves them unlocked and as a developer, you have to prevent each such method. And for a complex layout you describe, you have to use the Duplicate Layout option in the Layouts menu to fully duplicate the layout and then select your Locked fields, using the Inspector to change the behavior settings so that access is not permitted.

                      Once that is done, you'll need to control the layout switching, (An OnRecordLoad trigger can check the lock status and select the appropriate layout) to match up a given record with the desired layout.

                      This method sticks you with the job of making duplicate, identical layout modifications on each layout everytime you need to make a change to the layout.