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