Announcements
How to make fields mandatory conditionally(like based on some field value) with out using any code? Is this possible ?
The trigger is different when the user presses the next/previous step buttons - Rather than using Page_validator it calls webFormClientValidate (you put your pass/fail code inside where the comments are in the example) see the following link
Thanks LA for your answer. I am using this code in Web-From Step of Edit Type. Which part of code that is different for entity form and web form step(I got confused here).
Note: i included this code in function and am reusing this function as i am dealing with more fields.
Note, the above code is for an Entity form, there is slightly different code if using a Web Form step (the link in my previous post also has this).
If its a CRM cache issue, clear the cache <your portal url>/_services/about , if its a Chrome cache issue F12 with the debugger open then right click on the refresh button on the browser (chrome will then give you a clear hard cache option. (If you inspect the HTML in the debugger you can search for the code you updated to see if it has flowed through to the browser)
Yes. I have used the same code but sometimes its not working user can able to proceed without providing the data.But its happening sometimes only.I am not sure the reason.It might be the Cache issue?
Not possible without adding code (unless you are in a Web Form and have a conditional step with 2 different forms one with the mandatory and the other without it).
With JavaScript you add the 'required' class to the CSS of the element (to show the red asterix), then add a custom validator to put your logic for when it passes/fails the mandatory test. The code below adds a custom validator to validate that the emailaddress has been populated if email has been specified as a preferred contact method (as per https://docs.microsoft.com/en-us/powerapps/maker/portals/configure/add-custom-javascript
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'>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);
// Wire-up the click event handler of the validation summary link
$("a[href='#emailaddress1_label']").on("click", function () { scrollToAndFocus('emailaddress1_label','emailaddress1'); });
});
}(window.jQuery));
}
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156