cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Mikello-6626
Helper II
Helper II

Make field required in Portal based on value selected in another field

I am using Dataverse/Model driven app but displaying on a Portal.

 

I have two fields:

myschema_OtherPresentation  - Custom Choice field (Yes, No, Blank) - appears as radio button

myschema_DescribethisOtherPresentation - - Text field

 

If someone chooses "Yes" for myschema_OtherPresentation, then make myschema_DescribethisOtherPresentation required. Both fields are on the same tab and there is a Next button after this tab.  However, choosing Yes/No does not change a section or tab etc. so I believe I can't use Advanced Form Steps. 

 

Right now I am using this Javascript but don't know what is wrong with this:

https://docs.microsoft.com/en-us/powerapps/maker/portals/configure/add-custom-javascript 

 

 

 

 

 

 

 

 

      $(document).ready(function () {
         if (typeof (Page_Validators) == 'undefined') return;
         // Create new validator
         var newValidator = document.createElement('span');
         newValidator.style.display = "none";
         newValidator.id = "myschema_DescribethisOtherPresentationValidator";
         newValidator.controltovalidate = "myschema_DescribethisOtherPresentation";
         newValidator.errormessage = "<a href='#myschema_DescribethisOtherPresentation_label'>Describe this Other Presentation is a required field.</a>";
         newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form
         newValidator.initialvalue = "";
         newValidator.evaluationfunction = function () {
            var contactMethod = $("#myschema_OtherPresentation").val();
            if (contactMethod != 669080000) return true; // check if OtherPresentation is not 'Yes'
            // only require DescribethisOtherPresentation if OtherPresentation is Yes.
            var value = $("#myschema_DescribethisOtherPresentation").val();
            if (value == null || value == "") {
            return false;
            } else {
               return true;
            }
         };
 
         // Add the new validator to the page validators array:
         Page_Validators.push(newValidator);
 
         // Wire-up the click event handler of the validation summary link
         $("a[href='#myschema_DescribethisOtherPresentation_label']").on("click", function () { scrollToAndFocus('myschema_DescribethisOtherPresentation_label','myschema_DescribethisOtherPresentation'); });
      });

 

 

 

 

 

 

 

 

 

Yes value is 669,080,000 in my option set

No value is 669,080,001

 

 

@OliverRodrigues 

1 REPLY 1
Mikello-6626
Helper II
Helper II

Any replies appreciated

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,667)