I wanted to create an example of Model-Driven App view where a user could set the value of a Yes/No Choice, which would in turn, toggle the visibility of a specific section within the view.
I created a Solution.
From my solution, I created a Table in the Dataverse, called Sample 3 - Items
.
The table consisted of the following fields:
ShowSection1
– Choice column, Yes/NoSection1Text
– Text column, will be added toSection1
ShowSection2
– Choice column, Yes/NoSection2Text
– Text column, will be added toSection2
ShowSection3
– Choice column, Yes/NoSection3Text
– Text column, will be added toSection3
I then created a Model-Driven App called Sample 3 - Model-Driven App - Show or Hide Section with JavaScript
.
I added three sections to the Information Form
for Sample 3 - Items
and named them section1
, section2
, and section3
.
I added the toggles to the main section, and then added each SectionXText
field to the appropriate section.
I created a JavaScript file to handle the toggling of sections whenever the form loaded or whenever one of the values changed.
I uploaded the code, as a Web Resource, to my solution and wired it up according to the steps at Walkthrough: Write your first client script in model-driven apps – Power Apps | Microsoft Learn.
I published my app and then tested it out, and everything worked, 1st, 2nd … 10th try! Had some JavaScript challenges I had to work through.
Download the complete solution at Sample3Solution_1_0_0_1.zip and play around with it yourself!
Enjoy!
Discover more from Matt Ruma
Subscribe to get the latest posts sent to your email.
Great work! , and added to the collection.
https://msdynamicsconsulting.com/Solutions/Details/b2e66bbd-4f21-45d3-5446-08dc637513cc/toggle-sections-in-a-model-driven-app