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

Notifications

Announcements

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,368 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,434 Super User 2025 Season 2 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 74 Super User 2025 Season 2

#2
Jerry-IN Profile Picture

Jerry-IN 55

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard