Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Pages - General Discussions
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:
  • fm_skeller Profile Picture
    277 Super User 2025 Season 1 on at
    Re: Custom Javascript web pages power portal

    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



  • ahilisa Profile Picture
    32 on at
    Re: Custom Javascript web pages power portal

    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. 

     

  • Lucas001 Profile Picture
    2,182 Super User 2025 Season 1 on at
    Re: Custom Javascript web pages power portal

    Hi @ahilisa,

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

     

  • ahilisa Profile Picture
    32 on at
    Re: Custom Javascript web pages power portal

    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). 

  • oliver.rodrigues Profile Picture
    9,315 Most Valuable Professional on at
    Re: Custom Javascript web pages power portal

    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?

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

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 69 Super User 2025 Season 1

#2
oliver.rodrigues Profile Picture

oliver.rodrigues 49 Most Valuable Professional

#3
Jon Unzueta Profile Picture

Jon Unzueta 43