Hi all,
I am using Custom portal in PowerApps portals
In my portal page I have radio buttons with two options(Yes and No)
I need to to set mandatory validation for few fields based on radio button selected value
How can I achieve this using JavaScript/JQuery
Thanks in advance
Regards,
Babu
please disregard previous post.
cannot confirm that required field does not work when field is disabled
I used the metadata required setting with a required message for the field in question.
In javascript/jquery I disable/enable the field based on a dropdown.
when the field is disabled, the metadata validation/required is not done
when the field is enabled, the metadata validation/required is done.
Hi Clofly
No worries and thank you for your effort.
I could able to fix my problem by adding 4 newValidators as Justin told
Regards,
Babu
Hi Bahu,
Sorry for keeping you waiting, it took nearly 2 hours to fix some issues of my portal.
I have answered you in the new thread, please kindly check it. :)
Regards,
Clofly
Hi Babu,
for 4 fields should create newValidator object same like before and push the object to Page_Validators.push ( Page_Validators.push(newValidator))
Thanks
Justin Jose
Hi Clofly,
Thanks for your quick response. I will do that
As I don't have much time, I raised a new thread
Regards,
Babu
Hi Babu,
I'm trying to achieve your requirement in Potal, but currently my Portal is stuck at update, it needs some time to get updated and then research your new question.
It seems that you created a new thread, could you kindly mark the current thread as verified to close it if my code would work for validation? It would be really appreciated.
I will answer you in that new thread.
Regards,
Clofly
Hi Clofly,
Thanks for your response.
With your code I could able to implement validation for one field.
I need to set mandatory for 4 fields. How can I implement this
Please help me
Regards,
Babu
Hi Babu,
Please take following code as reference:
$(document).ready(function() { // Add event validator 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 = "Email is a required field."; newValidator.evaluationfunction = function() { if (!$('#new_acceptance_0').is(':checked') && $('#new_acceptance_1').is(':checked')) { if ($('#emailaddress1').val() == "") { return false; } else { return true; } } else { return true; } }; Page_Validators.push(newValidator); // Add validator element $("#new_acceptance_0").change(function() { if (this.checked) { $("#emailaddress1").attr('aria-required', "false"); $('#emailaddress1').parent().prev().removeClass("required"); } }); $("#new_acceptance_1").change(function() { if (this.checked) { $("#emailaddress1").attr('aria-required', "true"); $('#emailaddress1').parent().prev().addClass("required"); } }); })
It consists of two part:
1. Create a logic validator(newValidator variable) to prevent submit event and throw error message when specific condition meets.
2. Create an element validator, if specific condition meets, add "required" class to parent label of field.
e.g:
If Acceptance field equals "Yes", then set Email field to be mandatory.
1. By default:
2. When "Yes" button is checked, add red "*" character to Email label.
(If switch to "No", the element will be removed.)
3. Error message will appear if "Acceptance" equals "Yes" and Email field is empty.
Core logic: return false if
-> radio button 1 is not checked and radio button 2 is checked
->> if email field is emplty
The article below introduced how to add custom validator.
https://docs.microsoft.com/en-us/powerapps/maker/portals/configure/add-custom-javascript
Regards,
Clofly
Daivat Vartak (v-9d...
225
Super User 2025 Season 1
Muhammad Shahzad Sh...
106
Most Valuable Professional
Eugen Podkorytov
102