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 / For Power portal, make...
Power Pages
Unanswered

For Power portal, make field mandatory, non mandatory dynamically.

(0) ShareShare
ReportReport
Posted on by

I want to make email address field mandatory when method of contact is selected as email, and make phone as mandatory when phone is selected. when email is selected phone should be non mandatory and vice versa. I want to achive this functionality on power portal. Thanks.

Categories:
I have the same question (0)
  • ArchitectMadhan Profile Picture
    1,584 on at

    @Anonymous, To make the email address field mandatory when the method of contact is selected as email, and make the phone field mandatory when phone is selected, you can use JavaScript and Web Forms in Power Pages Portals. Here's how you can achieve this functionality:

    Open the Power Pages Design Studio.

    Navigate to the web page where the form is located or create a new web page for the form.

    Add a Web Form component to the web page and configure it to display the desired form.

    In the Web Form component properties, set the "Entity Name" to the appropriate entity and the "Form Name" to the desired form.

    Save the changes and switch to the "Web Template" tab.

    In the web template, locate the script section and add the following JavaScript code:

    javascript
    "<script>
    $(document).ready(function() {
    // Change the field names below to match your field names
    var emailField = 'emailaddress';
    var phoneField = 'telephone1';
    var methodOfContactField = 'methodofcontact';

    // Get the field controls
    var emailControl = $('#' + emailField);
    var phoneControl = $('#' + phoneField);
    var methodOfContactControl = $('#' + methodOfContactField);

    // Set initial field requirements based on the selected method of contact
    toggleFieldRequirement();

    // Toggle field requirement based on the selected method of contact
    methodOfContactControl.change(function() {
    toggleFieldRequirement();
    });

    function toggleFieldRequirement() {
    var methodOfContact = methodOfContactControl.val();

    if (methodOfContact === 'email') {
    emailControl.prop('required', true);
    phoneControl.prop('required', false);
    } else if (methodOfContact === 'phone') {
    emailControl.prop('required', false);
    phoneControl.prop('required', true);
    } else {
    emailControl.prop('required', false);
    phoneControl.prop('required', false);
    }
    }
    });
    </script>"

    Update the field names in the JavaScript code to match the field names in your form. Replace 'emailaddress', 'telephone1', and 'methodofcontact' with the actual field names from your entity.

    Save and publish the changes to the Power Apps Portal.

    After following these steps, the email address field will be mandatory when the method of contact is selected as email, and the phone field will be mandatory when phone is selected. When the email method is selected, the phone field will be non-mandatory, and vice versa. The JavaScript code will dynamically update the field requirements based on the selected method of contact in the form on the Power Apps Portal.

  • oliver.rodrigues Profile Picture
    9,368 Most Valuable Professional on at

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 70 Super User 2025 Season 2

#2
Jerry-IN Profile Picture

Jerry-IN 55

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard