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');
    }
}
  • Suggested answer
    oliver.rodrigues Profile Picture
    oliver.rodrigues 4,052 on at
    RE: Set field as required on portal form based on option from dropdown

    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

  • Inogic Profile Picture
    Inogic 438 on at
    RE: Set field as required on portal form based on option from dropdown

    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!

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,432 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans