cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Can I reset a Radio Button with OnChange?

I've never been able to succesfully trigger an OnChange command. Right now I'm making a Form, in which depending on the selected Cabinet ("Gabinete" on my side) some of the later items are not present, which I've already programmed, but I need them to reset as well, I've managed to reset every radio button by creating a variable that turns on and off whenever a Form Submission is successful, with:

UpdateContext({FormSRREF1:true});;UpdateContext({FormSRREF1:false})

And of course the Radio Buttons - Reset parameter has "FormSRREF1".

 

The thing is, I want to reset those buttons by changing the Cabinet on the "Gabinete" Dropdown menu seen on the screenshot attached, I tried using the same exact code (that worked fine before) on the OnChange parameter of the dropdown menu, but it doesn't have the same results as the button.

 

Is there any way to make the OnChange parameter work as I intend? Am I missing something? Any help would be massively appreciated, thanks in advance 🙂 

7 REPLIES 7
RandyHayes
Super User
Super User

@Anonymous 

You're looking at this all as programming from what I can tell - PowerApps is not development and programming, so let's look at this from another approach.

 

What is the purpose of resetting the radio controls?

They should automatically be getting any value that is defined for them.  Is it the Items property of the Radio controls or the Default of the Radio controls that you are trying to change and have shown?

I was not clear on your purpose of this as you only mentioned - "some of the later items are not present"

 

Is it that you want them to be Blank selections? or that you want them to display something else?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Anonymous
Not applicable

Well, the idea behind the form is that the user will find himself using it multiple times, since we're trying to replace the paper maintenance sheets to a mobile app. So for 1 cabinet there's multiple items to check for, that's why there's an "OK" and a "Not OK" selection. The later items I mentioned were because, if there is a Cabinet for example, that doesn't even have lights, you shouldn't be able to check them, so I hide the visibility based on the cabinet selected.

 

The thing is that, as you can see the 2 options are only "OK" and "Not OK", but I defined on SharePoint the default value to be "N/A", which is the value I get if I reset the radio buttons on the App.

 

As I was testing I saw that If I changed cabinet without submitting the form, the "Lights" value that I checked as "OK" for the previous Cabinet I was checking, carried on to the next Cabinet that had no lights as an "OK" although it had to be reseted and marked as "N/A". I can now reset those radio buttons to the default value by submitting, but if a maintenance user changes the cabinet without submitting because he misread the cabinet label or anything, I want to make sure that every variable is reseted to default to avoid bad reports.

 

Sorry if it is a little bit complicated, I tried to put it on words as best as I could since I don't natively speak english 😅

RandyHayes
Super User
Super User

@Anonymous 

No worries on the language - you're doing just fine! 😁

 

So, the issue is with not Visible controls!  If you select "Ok" for lights and then change the cabinet to one without lights, then you get "Ok" in the Lights column of the record - when it should be "N/A".

 

Am I following your issue properly?

 

Also, how are you setting the Visible property of the radio controls that are not relevant to the cabinet- on the Control or the DataCard?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Anonymous
Not applicable

Yeah, you got it right 😁 basically I need my radio buttons to be blank again for the Form to submit those Items as "N/A" on the SharePoint. That's what's not working at least in the "OnChange" parameter of the Dropdown menu.

 

But the code on the first message does work on every other instance I tried.

 

And I'm controlling visibility with a large If command on every Card individually, for example on "Lights" it would be something along the lines of:

 

If(Cabinet.Selected.Value = Cabinet1; false; Cabinet.Selected.Value = Cabinet5; false; true)

 

But actually sorting among 30 cabinets or so

 

RandyHayes
Super User
Super User

@Anonymous 

As a slight side-note - I would consider using the Items of your dropdown to drive visibility of your datacards instead of the individual formulas on each with the business logic in them.

Example Items property of your Dropdown:

Table(
    {Value:"Cabinet 1", Items:["Luces", "Ventiladores", "Puertas", "Limpieza", "Identificacion"]},
    {Value: "Cabinet2", Items:["Ventiladores", "Puertas", "Limpieza"]}
)

Then set your Visible property on the Datacard, of the light for example, to:

   "Luces" in yourDropdown.Selected.Items

That is all you need.  There is no need for the redundant If statement to determine if true, then true.

 

Now, the above is not your issue, it is just a tip since you mentioned there are a lot of cabinet options.  This will isolate all of the logic for the visibility in one place and make it easier for you.

 

As for the saving to SharePoint, I would alter the Update property of your datacard to check the visibility and determine what to write.

Example Update property:

If(Self.Visible, yourCardRadioControl.Selected.Value, "N/A")

This way, any datacard that is not visible will just automatically be set to "N/A" regardless of what it had in it.

 

See if that helps you out.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Anonymous
Not applicable

Thanks a lot! I changed the Update property of every card, although it was something more like:

 

If(Self.Visible, yourCardRadioControl.Selected.Value)

 

Because, since the DataCard belongs to a Form, the Update property only accepts Record type arguments, so I couldn't include the "N/A" as the default value if the condition wasn't met, but it worked as intended despite this 😁 So right now whenever a DataCard is not visible due to the cabinet selection on the dropdown menu, it gets sent as "N/A".

 

And while I was happy with that and began constructing my second form, It didn't show any data on screen, and it was because the "Item" field of the Form was empty, so it only showed 1 of the 2 forms. I changed the Items from blank to:

 

Defaults('YourFormHere')

 

And when I did, not only I got to see both forms correctly on screen, but also the OnChange function I wrote:

 

UpdateContext({ResetRB: true});;
UpdateContext({ResetRB: false})

 

on the Cabinet dropdown menu started working, now every time I change Cabinet every Data Card Value gets reseted as I intended, it was kind of an accidental fix but if anything goes wrong I have like 3 layers of safety checks thanks to this thread, so really thank you!

 

I also added a reset function based not only on the variable assigned but also on the Data Card visibility itself like:

 

If(ResetRB; true; !Parent.Visibility; true; false)

 

 

But I couldn't implement the Table function you mentioned. The dropdown menu doesn't let me arbitrarily change the Items field as it asks for Records Values as well. But I have a workaround for that so I guess everything is solved now! Thanks a lot for your help and your patience 😊

RandyHayes
Super User
Super User

@Anonymous 

Yes, you can absolutely change the Items property on Dropdowns to whatever you want.  The Table formula I provided is accurate and works fine.  This will make maintaining your app much easier (to have your visible property set the way that I previously mentioned) as you will change visible attributes from the Items of your dropdown and not having to go through all the datacards and change formulas when you add or change cabinet info.

 

If your Update property was not working because your underlying column is not a text column but instead is a Choice column, then the formula should be:

{Value: If(Self.Visible, yourCardRadioControl.Selected.Value, "N/A")}

This will provide the Update with a record that has a Value column - and, assuming that "N/A" is a valid value in your underlying column, then all will work fine.

 

When you use Defaults(yourDatasource) in the Item property of the form, it is equivalent to setting your form DefaultMode to "New", or issuing a NewForm(formName) function as both will put the form into what is considered "new" mode.  In that mode, the form will automatically generate a Defaults(yourDataSource) for its underlying record property.

 

Unless you need the visible radio controls to reset, then there is no need for the context variable to reset them as the Update formula and the Visible property reference to the dropdown will control all the rest.

 

Glad you have something working at the moment.  As mentioned starting out in the first response, one of my goals in the response was to demonstrate that you were looking at your situation as a programming issue.  My point was that PowerApps is not programming, so what I presented was more of a "PowerApps Way" of doing things.  All about formulas and references to controls.

I hope that was helpful for you as you progress!

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (2,695)