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 / Custom Javascript web ...
Power Pages
Unanswered

Custom Javascript web pages power portal

(0) ShareShare
ReportReport
Posted on by 32

I have added custom JavaScript to a powerapps portal web page, the code I am using shows a field 2 when a particular selection (Yes) is made in field 1, field 2 does not appear on the form if no selection is made in field 1.  The issue I am havig is field 2 is not mandatory and the code is using .prop("required",true).

 

Field 1 is a dropdown field with the options Blank (before section) Yes or No. 

Field 2 is a multiselect field with 4 options. 

 

The show/hide element of the code is working correctly just not the mandatory step to make the user select an option in field 2 before moving to the next page. 

 

This is my code:

// if Sec C Q1 SC = Yes show Q2
$(document).ready(function() {
$("#recordclinical").change(SetFieldsVisibilityQC1);
$("#recordclinical").change();
});
function SetFieldsVisibilityQC1() {
var selectedValue = $("#recordclinical").val();
if (selectedValue === "352230000")
{
$("#recorded_label").closest("tr").show();
$("#recorded").prop("required",true).closest("tr").show();
$("#otherspecify_label").closest("tr").show();
$("#otherspecify").prop("required",false).closest("tr").show();
}
else
{
$("#recorded_label").closest("tr").hide();
$("#recorded").prop("required",false).closest("tr").hide();
$("#otherspecifyd_label").closest("tr").hide();
$("#otherspecify").prop("required",false).closest("tr").hide();
}
}

 

any advice what on what I am missing. 

Categories:
I have the same question (0)
  • oliver.rodrigues Profile Picture
    9,449 Most Valuable Professional on at

    Hi, is the field 2 mandatory at the dataverse level? or can you check if there is any form metadata associated with the field making it required?

  • ahilisa Profile Picture
    32 on at

    Field 2 is set as optional at dataverse level because its only required if field 1 is yes. Currently no metadata set, I set the field required using the metadata but this only makes it required all the time even when its not visible (i.e. field 1 is no). 

  • Lucas001 Profile Picture
    2,529 Super User 2026 Season 1 on at

    Hi @ahilisa,

    is there anything bound to the second .change() which could interfere or set value?

     

  • ahilisa Profile Picture
    32 on at

    I have removed that and its still not working. Also, I am not able to use metadata as the field doesn't appear in the list, this maybe because it is an multiselect field. 

     

  • fm_skeller Profile Picture
    277 Moderator on at

    Are you just setting the 'required' property of these fields? As far as I know, that does not prevent a portal user from submitting the form. 
    You could add a Custom Page Validator, as described here.
    For the validation function you could just use RequiredFieldValidatorEvaluateIsValid instead of a custom function.
    To mark the field as required, you can use something like

     

     

    $("#id_of_field2").closest("td").find("div.info").addClass("required");

     

    Don't forget to remove the validator if the field is no longer required based on user input



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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
DP_Prabh Profile Picture

DP_Prabh 51

#2
rezarizvii Profile Picture

rezarizvii 35

#3
oliver.rodrigues Profile Picture

oliver.rodrigues 33 Most Valuable Professional

Last 30 days Overall leaderboard