2 Replies Latest reply on Jun 16, 2014 8:32 AM by ShaylynJ

    validate required fields before using custom email button

    ShaylynJ

      Good Morning,

       

      I have a custom button that I am using as a email button so we could have a cc address added. The code I'm using is:

       

      form1.subform.Button3::click - (JavaScript, client)

       

      var oDoc = event.target;
      oDoc.mailDoc({
      bUI: true,
      cTo: "test@email.com",
      cCc: "cc@email.com",
      cSubject: "Title of the form",
      });

       

      Is there a way I can validate that 3 text fields are filled in when the user clicks the button?

       

      Thank you for any help you can provide.

       

        • 1. Re: validate required fields before using custom email button
          Magus069 Level 4

          to verify if a field is filled in you may use the if statement to check if the rawValue is null

          var boValidation = true;

          if (textfield1.rawValue == null){

               //Validation failed

               boValidation = false;

          }

          if null is not working it might be because it's a checkbox or radiobutton or dropdownlist, etc... cehck if value is 0

          if (chkBox.rawValue == 0){

               //Validation failed

               boValidation = false;

          }

          Now when you are about to send the email verify is the fields were filled in successfuly

          if (boValidation){

               var oDoc = event.target;

               oDoc.mailDoc({

                    bUI: true,

                    cTo: "test@email.com",

                    cCc: "cc@email.com",

                    cSubject: "Title of the form",

               });

          }

          • 2. Re: validate required fields before using custom email button
            ShaylynJ Level 1

            Thank you it worked! Code used for reference:

             

            var boValidation = true;

            if (form1.subform.name.rawValue == null || form1.subform.userid.rawValue == null || form1.subform.compname.rawValue == null)

             

            {

             

            //Change validation to null

            boValidation = false;

            app.alert("Please fill in the required fields.");

            }

             

            if (boValidation)

            {

            var oDoc = event.target;

            oDoc.mailDoc({

            bUI: true,

            cTo: "t...@domain.com",

            cCc: "c...@domain.com",

            cSubject: "title",

            });

            }