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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Set field as required on portal form based on option from dropdown

(0) ShareShare
ReportReport
Posted on by 15

I am using the below code to show/hide a field based on a selection in a dropdown box.  The show/hide feature is working correctly but I want to make the field that is shown mandatory but .attr('required', true); does not appear to be working. 

How can I achieve making input into this field mandatory? 

// Make vet reg required if the occupation is PVP

$(document).ready(function() {

$("#ahi_occupation").change(SetVetRegRequired);
$("#ahi_occupation").change();
});

function SetVetRegRequired() {
var selectedValue = $("#ahi_occupation").val();

if (selectedValue == "100000002")
{
    $("#ahi_vetreg_label").closest("tr").show();
    $("#ahi_vetreg").show().attr('required', true);
}
    else
{
    $("#ahi_vetreg_label").closest("tr").hide();
    $("#ahi_vetreg").hide().removeAttr('required');
    }
}
I have the same question (0)
  • Inogic Profile Picture
    682 on at

    Hi,

     

    You can use below code to set the field as required in the PowerApps Portal.

     

    if ($("#" + fieldName) != undefined) {

                 $("#" + fieldName).prop('required', true);

                 $("#" + fieldName).closest(".control").prev().addClass("required");

     

     

    Hope this helps!

  • Suggested answer
    oliver.rodrigues Profile Picture
    4,052 on at

    Please use PowerUsers forum for new Portal questions:

    powerusers.microsoft.com/.../PowerAppsPortals

    ------------

    Please refer to this article to set fields mandatory: docs.microsoft.com/.../add-custom-javascript

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 70

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans