web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / DOB required on check ...
Power Pages
Unanswered

DOB required on check - Javascript

(0) ShareShare
ReportReport
Posted on by 690

I have 2 validators in my custom code - the email one works perfect but the DOB one I can't get to pass when I populate a date.  The validator is supposed to check if DOB unknown is checked then a date is not needed in the DOB field.  If DOB unknown is not checked then a date is needed I get the  alert when DOB is unknown is NOT checked and DOB null but I can't get it to pass when I enter a DOB or if I check DOB unknown 

 

ctedesco3307_0-1696339914204.pngctedesco3307_1-1696339947999.png

 


 

 $(document).ready(function () {
      alert("todayemail2");
         
         if (typeof (Page_Validators) == 'undefined') return;
         // Create new validator
         var newValidator = document.createElement('span');
         newValidator.style.display = "none";
         newValidator.id = "emailaddress1Validator";
         newValidator.controltovalidate = "crb09_emailaddress1";
         newValidator.errormessage = "<a href='#crb09_emailaddress1_label' referencecontrolid='crb09_emailaddress1 ' onclick='javascript&colon;scrollToAndFocus(\"crb09_emailaddress1 _label\",\" crb09_emailaddress1 \");return false;'>Email is a required field.</a>";
         newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form
         newValidator.initialvalue = "";
         newValidator.evaluationfunction = function () {
            var contactMethod = $("#crb09_preferredcontactmethodcode").val();
            if (contactMethod != '476150001') return true; // check if contact method is not 'Email'.
            // only require email address if preferred contact method is email.
            var value = $("#crb09_emailaddress1").val();
            if (value == null || value == "") {
            return false;
            } else {
               return true;
            }
         };

         // Add the new validator to the page validators array:
         Page_Validators.push(newValidator);
{
      alert("todaydob");
         
        if (typeof (Page_Validators) == 'undefined') return;
         // Create new validator
         var newValidator = document.createElement('span');
         newValidator.style.display = "none";
         newValidator.id = "dobValidator";
         newValidator.controltovalidate = "crb09_dateofbirth";
         newValidator.errormessage = "<a href='#crb09_dateofbirth_label' referencecontrolid='crb09_dateofbirth ' onclick='javascript&colon;scrollToAndFocus(\"crb09_dateofbirth _label\",\" crb09_dateofbirth \");return false;'>DOB is a required field.</a>";
         newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form
         newValidator.initialvalue = "";
         newValidator.evaluationfunction = function () {
            var contactMethod = $("#crb09_dobunknown").is(':checked');
            if (contactMethod = true) return false; // check if dobunknown checked.
            // only require dob if unknown is not checked.
            var value = $("#crb09_dateofbirth").val();
            if (value == null || value == "" ) {
            return false;
            } else {
               return true;
            }
         };

         // Add the new validator to the page validators array:
         Page_Validators.push(newValidator);
      }});
Categories:
I have the same question (0)
  • Verified answer
    ctedesco3307 Profile Picture
    690 on at

    I got it 

     


    $(document).ready(function () {
    alert("todaymm1");
     
    if (typeof (Page_Validators) == 'undefined') return;
    // Create new validator
    var newValidator = document.createElement('span');
    newValidator.style.display = "none";
    newValidator.id = "dobValidator";
    newValidator.controltovalidate = "crb09_dateofbirth";
    newValidator.errormessage = "<a href='#crb09_dateofbirth_label' referencecontrolid='crb09_dateofbirth ' onclick='javascript&colon;scrollToAndFocus(\"crb09_dateofbirth _label\",\" crb09_dateofbirth \");return false;'>DOB is a required field.</a>";
    newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form
    newValidator.initialvalue = "";
    newValidator.evaluationfunction = function () {
    var dobMethod = $("#crb09_dobunknown").is(':checked');
    if (dobMethod != false) return true; // check if dobunknown checked.
    // only require dob if unknown is not checked.
    var value = $("#crb09_dateofbirth").val();
    if (value == null || value == "" ) {
    return false;
    } else {
    return true;
    }
    };
    // Add the new validator to the page validators array:
    Page_Validators.push(newValidator);


    });

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 71

#2
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard