9 Replies Latest reply on Mar 3, 2012 2:00 AM by ebassily

    Making fields active based on values in another field

    ebassily

      I have a boolean field with yes or no values (call it field #1). I would like to make some dependent fields active (with data entry allowed into them) when the value of field #1 is "yes", and inactive (with no data entry capability) when the value of field #1 is "no". I tried conditional formatting, but it doesn't give me what I need. Does anyone have a solution or a workaround for that?

        • 1. Re: Making fields active based on values in another field
          BowdenData

          ebassily wrote:

           

          I have a boolean field with yes or no values (call it field #1). I would like to make some dependent fields active (with data entry allowed into them) when the value of field #1 is "yes", and inactive (with no data entry capability) when the value of field #1 is "no". I tried conditional formatting, but it doesn't give me what I need. Does anyone have a solution or a workaround for that?

           

          Ebassily,

           

          I am not aware of a way to restrict specific fields using privilege sets. You can allow or disallow editing of fields at the record level using privilege sets, but that is not what you seem to be asking for. A few ways I can suggest for this.

           

          1) Attach a script to the field(s) you want to control. When the user clicks into the field, the script will perform the desired checks and if all okay, go to the field. If not okay, exit the field, give the user an error message, etc. This is kind of the old way of doing this. Downside is that the field "flashes" when you click on it. FM treats it as a button, so it gives you a visual indicator that you have clicked it. If you go this route, I suggest turning off the feature the change the cursor to a hand.

           

          1a) Attach an OnObjectEnter script trigger to the field(s). Script can take action according to your rules. The more modern approach.

           

          2) If you want to hide and reveal the fields you want to control, you can use the old hidden portal trick. This can be useful in some circumstances, but it will clog up your graph with extra relationships and quite possibly slow your dB down. Shouldn't be an issue though if you only have one or two of these in your system. If you go crazy with this, then all bets are off.

           

          HTH.

           

          Doug de Stwolinska

          • 2. Re: Making fields active based on values in another field
            ninja

            If you haven't already seen it, there is a very similar discussion here:

             

            https://fmdev.filemaker.com/thread/62940

             

            HTH

            • 3. Re: Making fields active based on values in another field
              timwhisenant

              Hi,

              Maybe this will accomplish what you need.

               

              https://fmdev.filemaker.com/docs/DOC-2290

               

               

              Tim W

              • 4. Re: Making fields active based on values in another field
                Stephen Huston

                Another method that hasn't been mentioned is, at the field definition level, you can set field validation to return false if the other field does not contain the correct entry to allow editing of this field.

                 

                [ Validation by Calculation:  FieldUsedAsFlag = "Correct flag here" ]

                 

                This will force them to leave the field without commiting the change if the flag is not correct for allowing editing. This will restrict the field system-wide until the flag field contains the correct value.

                 

                The script trigger approach also works, but has to be setup on each instance of the field you want to restrict on each layout where it appears. It has the benefit of NOT being system-side if you are only trying to control what happens on one or two layouts.

                 

                Stephen Huston

                • 5. Re: Making fields active based on values in another field
                  Stephen Huston

                  There is also two other methods which can cause the field to be unenterable unless the correct conditions exist.

                   

                  The first, putting a script on the field so the field is a button which runs a script which exits the field if conditions are not met, or enters it if they are. You should take the field out of the tab order so it cannot be reached without using the button.

                   

                  The other is a bit more complex but actually can make the field disappear as well as not be enterable until the right conditions are met. That requires setting up a special TO and Relationship which will be valid only when the conditions are correct, often using calc fields in the relationship. Then you place the field from that related instance of the table in a small portal using that relationship, and the field will not be enterable until the relationship is valid. Then you can also use custom formating to make it appear invisible if the related record count for that portal is zero.

                   

                  This vanishing portal trick has been around for many years, and I learned it from one of Que Publishings old Special Edition Using FileMaker books at least a decade ago.

                   

                  So now you have another tool to pick from.

                  • 6. Re: Making fields active based on values in another field
                    BowdenData

                    Tim,

                     

                    Looked at your demo file. As FYI, I noticed that you are toggling the value in the control field using

                     

                         "Abs (  GrayoutFields::GrayoutCondition  )  - 1"

                     

                    This toggles the value in the field between 0 and -1. An alternative is to use

                     

                         "not GrayoutFields::GrayoutCondition"

                     

                    This toggles the field value between 0 and 1. Makes it easy to search in the field (behind the scenes) for it being equal to 1, summing the field across records (tells you how many records have the field enabled), and so forth.

                     

                    HTH.

                     

                    Doug de Stwolinska

                    • 7. Re: Making fields active based on values in another field
                      timwhisenant

                      Thanks Doug,

                       

                      I meant to change that before I finished the file. Michael Horak mentioned it to me in another post. Thanks for the catch. I will update the file.

                       

                       

                       

                      Thanks,

                       

                      Tim

                      • 8. Re: Making fields active based on values in another field
                        ebassily

                        Thanks a lot Doug for your quick and informative reply. I used the OnObjectEnter trigger and it worked. I guess I will use conditional formatting as well to mask out the fields when the validation fails. I wanted to do this from the beginning, but I also needed a way to disallow entry into the fields, because experienced users can find the masked fields and enter values into them when they shouldn't. Thanks again. You've been very helpful.

                        • 9. Re: Making fields active based on values in another field
                          ebassily

                          Thanks everybody for your responses and help. I used the script trigger approach and it worked, and I will also use the conditional formatting to add some style to the layout. Thanks again.