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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Show all validation er...
Power Pages
Answered

Show all validation errors at the same time

(0) ShareShare
ReportReport
Posted on by 167

I am using the page validator class to add client side validation. I have it working by using the code below but it only shows 1 error at a time despite adding multiple validators. I'm wondering how do we show all validation errors to the user at the same time.

Screen Shot 2023-03-20 at 2.09.11 PM.png

 

if (window.jQuery) {
(function ($) {
$(document).ready(function () {
if (typeof (Page_Validators) == 'undefined') return;
// Create new validator
var newValidator = document.createElement('span');
newValidator.style.display = "none";
newValidator.id = "emailaddress1Validator";
newValidator.controltovalidate = "emailaddress1";
newValidator.errormessage = "<a href='#emailaddress1_label' referencecontrolid='emailaddress1 ' onclick='javascript&colon;scrollToAndFocus(\"emailaddress1 _label\",\" 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 = $("#preferredcontactmethodcode").val();
if (contactMethod != 2) return true; // check if contact method is not 'Email'.
// only require email address if preferred contact method is email.
var value = $("#emailaddress1").val();
if (value == null || value == "") {
return false;
} else {
return true;
}
};

// Add the new validator to the page validators array:
Page_Validators.push(newValidator);

});
}(window.jQuery));
}

 

Documentation I'm following: 

https://learn.microsoft.com/en-us/power-apps/maker/portals/configure/add-custom-javascript

Categories:
I have the same question (0)
  • Verified answer
    Fubar Profile Picture
    8,501 Super User 2026 Season 1 on at

    It helps if you include your code that you are having the issue with, the code provided is only 1 validation.

     

    You need to create multiple validation objects e.g.  var newValidator = document.createElement('span'); for one and the respective validation etc for it and var newValidator2 = document.createElement('span'); for another and the respective validation for it, and then push them separately to the the Page_Validators e.g. 

    Page_Validators.push(newValidator); 

    Page_Validators.push(newValidator2);

  • gng Profile Picture
    167 on at

    It's working fine now. I marked your answer as the solution as that was how I was doing it anyway. It was an issue with an exception from the code.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
11manish Profile Picture

11manish 41

#2
omkarsupreme Profile Picture

omkarsupreme 40

#3
Valantis Profile Picture

Valantis 37

Last 30 days Overall leaderboard