11 Replies Latest reply on Mar 5, 2014 5:50 AM by dhaberm

    Validating two fields, either with a value

    dhaberm

      I am trying to do something that seemed so easy in other programming languages that I have used, but can seem to crack in here...

       

      Here's what I am trying to do.

       

      I have an age field that is required. If the age is unknown, rather than making a user type unknown (or something else and change the field to alphanumeric). I would a check box next to the age field. If age is unknow, then they can check the box and the age field would not be enterable. If they got an age, then the Check box would not be selectable...and validation for the form would make sure one or the other is selected. looks something like this...

       

      Age.png

       

      thanks

        • 1. Re: Validating two fields, either with a value
          jmrusch

          Make the Age Unknown checkbox a button. The checkbox should be tied to a value list that has the number 1 as its only entry and set so that actual data entry into the field is turned off in Browse mode; entry into the field is only done via the button's script. The script attached to the button would do this:

           

          SetField ( Age Unknown ; If ( Age Unknown = 1 ; "" ; 1 ) )      /* Toggles Age Unknown checkbox between being checked or unchecked */

          SetField ( Age ; If ( Age Unknown = 1 ; "" ; Age ) )                /* Clears Age if Age Unknown just got checked; otherwise leaves it alone */

           

          Age needs to have a script trigger on it. That script trigger would probably be an OnObjectEnter, and tied to a script that looked something like:

           

          If ( AgeUnknown = 1 )

              /* if the Age Unknown box is checked, just leave the Age field */

              Go To Field []

          EndIf

           

          Hope that helps, and I also hope someone posts other ideas of how to approach this. I've dealt with similar situations as described above, but I always feel like there must be a better way.

           

          Julie

          • 2. Re: Validating two fields, either with a value
            ariley

            As usual in FileMaker, you can do this in multiple ways:

             

            1. Put a trigger that runs a script on the age field so it cannot be modified if the checkbox field has a value "1". If true, then clear the value of age.

             

            Put a record-level validation in Manage Security so the field can only be modified if isEmpty(age field). 

             

            Best regards,

             

            Agnes Riley

            ZeroBlue

            • 3. Re: Validating two fields, either with a value
              erolst

               

              Julie Rusch wrote:

              SetField ( Age Unknown ; If ( Age Unknown = 1 ; "" ; 1 ) )      /* Toggles Age Unknown checkbox between being checked or unchecked */

              If ( AgeUnknown = 1 )

                  /* if the Age Unknown box is checked, just leave the Age field */

               

               

              Julie -

               

              one of the advantages of using a Boolean valuelist is that you can do things like these with more natural expressions:

               

              Set Field [ ageUnknown ; not ageUnknown ) , and

              If ( ageUnknown ; …

               

              But here's a sample that takes a somewhat different approach:

              • 4. Re: Validating two fields, either with a value
                jmrusch

                Thanks for your example file. It's much more elegant than my way and has the advantage of only needing one script instead of two. It also does a better job of "locking" one field when anything is set/entered in the other field.

                 

                And, yeah, I would just say "If ( Age Unknown ; ... )" in my solutions but I've known people who are confused by that notation as well as the concept of having the checkbox tied to a value list with just a 1 in it, so I was trying to be more detailed in my answer.

                 

                Thanks,

                Julie

                • 5. Re: Validating two fields, either with a value
                  davehob

                  That's really neat.

                  Dave.

                  • 6. Re: Validating two fields, either with a value
                    dhaberm

                    Thanks for the example file...that seems to work greast, but it is not working in my file. I am not sure what I am doing wrong, I copied the trigger in and changed the names for my fields and file???

                    • 7. Re: Validating two fields, either with a value
                      erolst

                      dhaberm wrote:

                      I copied the trigger in and changed the names for my fields and file???

                       

                      Which isn't really necessary; you just need to reference your (functionally equivalent) fields within the two assignments that use GetFieldName(). (The point being that you can rename these fields without breaking the functionality.)

                       

                      Why don't you post your script (or file)?

                      • 8. Re: Validating two fields, either with a value
                        erolst

                        Julie Rusch wrote:

                        And, yeah, I would just say "If ( Age Unknown ; ... )" in my solutions but I've known people who are confused by that notation as well as the concept of having the checkbox tied to a value list with just a 1 in it, so I was trying to be more detailed in my answer.

                        So why not start educating the masses?

                        • 9. Re: Validating two fields, either with a value
                          dhaberm

                          Sorry my reply was kind of confusing...I created a trigger exactly like you did, with my if statement lookin glike this...

                           

                          Let ( [

                          af = GetValue ( Substitute ( GetFieldName ( EMS Arrivals::Age ) ; "::" ; ¶ ) ; 2 ) ;

                          uf = GetValue ( Substitute ( GetFieldName ( EMS Arrivals::Age Unknown ) ; "::" ; ¶ ) ; 2 ) ;

                          active = Get ( ActiveFieldName ) ;

                          Other = Case ( active = af ; uf ; af )

                          ] ;

                           

                           

                          not IsEmpty ( GetField ( Other ) )

                           

                           

                          )

                          • 10. Re: Validating two fields, either with a value
                            erolst

                            Well, I renamed my table and fields to your names, copied over your version of the calculation into my If[], and it (still) all works …

                             

                            Sure you're using an OnObjectEnter trigger with this script for both fields? (and as a sanity check: both fields are set to allow entry in Browse mode?)

                            • 11. Re: Validating two fields, either with a value
                              dhaberm

                              Ok, I walked away and came back and found my mistake, I am almost there. I have the releationship between the field working, now I just need to validate that one or the other is entered!!!

                               

                              Thanks!!!