12 Replies Latest reply on Oct 17, 2008 6:45 AM by carrie

    Mandatory field if checkbox is checked?



      Mandatory field if checkbox is checked?



      Hey guys!


      How can I make it so that if my checkbox is checked yes,

      the customer name and contact number fields would then be required?

      It's not that I require it to be "not empty"

      rather I require it to have a name and number only if the checkbox has yes checked.


      Thanks again! 

        • 1. Re: Mandatory field if checkbox is checked?

          Enter the following calculation under Validation in the field options in Manage Database:

          check = "no" or (check = "yes" and not IsEmpty(Self))

          Substitute check for your checkbox field.

          If you want to, you can enter a custom error message for when this validation triggers in this dialog.

          This takes care of the validation, however it does not "do" anything when you change the checkbox field.
          I asssume you may want to move the cursor to the customer name when you select yes. For this you either needs to use a script trigger plugin or place a button over your checkboxes that runs a script.
          • 2. Re: Mandatory field if checkbox is checked?


            Hi thanks for helping me, but I can still make a new record without having to put info into the name and contact fields, after checking yes.

            After I check yes, you mentioned I can make the cursor move to the customer name field and after entering the name that can I make it go to contact # field and enter the phone number; and have both of those fields be mandatory only if the yes box is checked?

            You can probably tell I'm a n00b.

            Can I bug you again to tell me how to make this happen, so that a user cannot leave the name and # fields blank after they check yes?

            Thanks again for your assistance!

            I really appreciate your time and help.


            • 3. Re: Mandatory field if checkbox is checked?
                 When you say "require" what sort of behavior do you mean?  If you mean new fields should appear requesting input then use a button that runs a script that toggles you to a new layout which includes the extra fields.  On the new layout include an identical button that toggles you back to the first layout.  You can add some extras to the script like toggling the checkbox field, going to the Names field, etc.  It really just depends on how you want the workflow.  
              • 4. Re: Mandatory field if checkbox is checked?

                I just want it so that if an agent selects that "yes" its a cash order, they will then be required to put a name into the customer name field and a contact phone number in the contact # field.

                I already have the fields on my same layout, I wanted to keep them there.

                I just only want it to be mandatory that the agents fill them out if they selected yes instead of no.

                Thanks a bunch!


                • 5. Re: Mandatory field if checkbox is checked?

                  As you know Filemaker can require "Not empty" as a validation option to the field definition.  However, this does not become active unless a user tries to enter text in the field.  Thus it really only prevents text from being deleted.  Also field validation only works on one field at a time and you want to require both Name and Contact numbers.  


                  I'd consider inserting a "Done" button that the user must select when data entry is complete.  This would then run a script that would check for missing data.  In the case where "cash order" is checked it would verify that the Name and Contact fields are not empty (e.g. with a 'not IsEmpty()' calculation) and would return the appropriate error message.    

                  • 6. Re: Mandatory field if checkbox is checked?

                    Hi carrie,


                    There may be a better way to do this, but here is one way you can try:


                    The fields we are working with will be:

                    1.  customername (text)

                    2.  phonenumber (text)

                    3.  cashorder (text...  change the field to a radio button using a 'yes' or 'no' value list) 

                    Go to Manage > Database > highlight the cashorder field > click on options > Validation tab > check Validated by calculation > click on the Specify... button.  Enter the following calculation:


                    If ((cashorder = "yes" and IsEmpty (customername) ≠ 1 and IsEmpty (phonenumber) ≠ 1) or cashorder = "no"; 1 ; "fail" )


                    What we are trying to validate for the cashorder field are two things: 1. cashorder is selected 'yes' and there is a value in customername and phonenumber or 2. cashorder equals 'no.' 

                    If cashorder equals 'yes' but the customername or phonenumber fields are empty or if only one field has a value, the cashorder field will not validate. 


                    Let's go back to the cashorder > Options > Validation tab.  Click on "Display custom message if validation fails."  Here, you can enter a custom message such as "Please enter a customer name and contact number" that will display every time the validation criteria is not met.


                    Now, if a customer selects 'no' they will be able to move freely throughout the database.  If the customer clicks 'yes' (with no values in the customername and phonenumber fields) they will be prompted with a message asking them to enter data.  After entering the values in the customername and phonenumber fields, they will be good to go.


                    Hope this helps.  Let me know if you need any further clarification.



                    FileMaker, Inc. 



                    • 7. Re: Mandatory field if checkbox is checked?
                         I agree that ts_turtle's suggestion works fine. However, it will cause an error message to pop up as soon as the 'cash order' field is checked.  The user might find this a little annoying if they haven't finished entering information yet. 
                      • 8. Re: Mandatory field if checkbox is checked?

                        Hi Carrie


                        The key here is applying the validation to the name and phone fields. In this solution, I am using text fields cash_order, name and phone. On the layout, the cash_order field displays Yes and No as radio buttons.


                        To establish a default result for cash_order, set the field options to auto-enter data "No". This means that each new record will have No in the field by default. Obviously, it can be changed to Yes and that is when the following validation will kick in.


                        The field option for the name field is as follows:


                        1. Validated by calculation: 

                               ( cash_order = "yes" and not IsEmpty ( Self ) ) or cash_order = "no" 

                           Importantly, you must UNCHECK the option at the bottom of the calculation dialog 'Validate only if field has been modified'. This is because we will usually want the validation to trigger when the cash_order field has been modified. 

                        2. UNCHECK 'Allow user to override during data entry' 

                        3. Add a custom message when validation fails such as: "You must enter a name when it is a cash order."


                        Repeat this with an appropriate custom message for the phone field.


                        And that is it. When the user tries to commit the record, the validation will trigger if the cash_order field is Yes and they have left either name or phone empty. 

                        • 9. Re: Mandatory field if checkbox is checked?
                          Carrie, you could add an invisible button over the "yes" check box.

                          This button triggers a script that does two things:

                          Sets the checkbox field to yes using Set Field.
                          places the cursor in the customer name field with the Goto Field command
                          • 10. Re: Mandatory field if checkbox is checked?


                            If you implement my solution you will see that there is no need for a button or a script. Ockhams Razor applies - simplest is best. 

                            • 11. Re: Mandatory field if checkbox is checked?

                              I agree, somehow I missed your post.
                              • 12. Re: Mandatory field if checkbox is checked?

                                Thanks so much for all your help guys, 

                                It works now!!!

                                I really appreciate your time and patience with me!