cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Serviced2000
Helper IV
Helper IV

Gallery Checkboxes and Toggles Uncheck Automatically

Hi Everyone,

 

I'm building a simple app where I have a list of individuals that I need to be able to check / select or unselect from the gallery screen (screenshot in attachments). I'm using these Patch() functions to update a Sharepoint list : 

 

For OnCheck

Patch('Associate Consultants', LookUp('Associate Consultants', ID=BrowseGallery1.Selected.ID), {Selected: "Yes"})

 

For On UnCheck

Patch('Associate Consultants', LookUp('Associate Consultants', ID=BrowseGallery1.Selected.ID), {Selected: "No"})

 

Note: Selected is a column name in my Sharepoint list (I'm not sure if it's a reserved word in PowerApps). This is for use in a flow at a later stage where Sharepoint doesn't like True / False columns.

 

What happens is that all works really well when I add the Patch for OnCheck, but as soon as I add the Patch for On Uncheck, the toggles (checkboxes do the same thing) behave strangely. If I toggle one gallery item it may (or may not) uncheck itself. If I toggle two they will both uncheck. If I toggle 3 they will stay toggled, until I uncheck one and they will ALL uncheck.

 

I'm certain I've missed something very basic here but all my research (read: Googling) has pointed me to solutions where checking multiple boxes / toggles is the preferred behaviour, so I can't see why this is happening when I don't need it.

 

Any help would be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Serviced2000 ,

I posted this one a short time ago - the second bit is similar to what you need - using this syntax, yours I believe would be something like

ForAll(
   RenameColumns(
      YourGalleryName.AllItems,
      ),
      "ID",
      "IDRef"
   ),
   UpdateIf(
      'SP list',
      ID = IDRef,
      {
         Consultant_Selected:
         If(
            Toggle4.Value,
            "Yes",
            "No"
         )
      }
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

View solution in original post

21 REPLIES 21
WarrenBelz
Super User
Super User

Hi @Serviced2000 ,

Firstly, you are correct in that Selected is a reserved word and you should rename this control as soon as possible.

If this does not fix the issue, you can look at a Default value which you can set with a Variable to the value of the control on the OnChange but on the condition that ThisItem.IsSelected is true.

Have a go at this first - happy to help further.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Thanks @WarrenBelz - I changed the column name to Consultant_Selected but that hasn't changed the behaviour. When it comes to changing the default with a variable where would I put the ThisItem.IsSelected bit - in the OnCheck / On Uncheck Actions? 

 

Apologies - should probably have mentioned I'm a complete novice in this space...

Hi @Serviced2000 ,

On the Default.

I just did some basic testing, not necessarily mirroring yours, but I did the following on a checkbox in a gallery.

On both the OnCheck and OnUncheck (add your other code as well) and replace control  name with yours.

UpdateContext({vCheck:YourCheckboxName.Value})

 The Default of the Checkbox

If(ThisItem.IsSelected,vCheck)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Sorry @WarrenBelz,

 

Still no - now, when I click the second toggle it goes on and then off and the first toggle switches to off as well. Apologies - I've probably missed something really basic here. I've added a snip of the toggle properties which will hopefully show what I've done. If this looks correct I might kill this app altogether and start afresh in case I've messed anything up in the earlier stages...

Thanks @Serviced2000 ,

Did you change the Default of Toggle4 to

If(ThisItem.IsSelected,vCheck)

 

Thanks @WarrenBelz ,

 

I'm pretty sure this is in the right place...

 

 

Gallery3.PNG

Hi @Serviced2000 ,

UPDATE - 

A bit more testing and I am getting the same strange behavior.

The following works a bit better - but clunky and does a few other strange things.

Default

If(ThisItem.IsSelected,vCheck)

OnCheck

Select(Parent);
Patch(
   'Associate Consultants', 
   LookUp(
      'Associate Consultants', 
      ID=BrowseGallery1.Selected.ID
   ), 
   {Selected: "Yes"}
;)
Refresh('Associate Consultants');
UpdateContext({vCheck:true})

OnUncheck

Select(Parent);
Patch(
   'Associate Consultants', 
   LookUp(
      'Associate Consultants', 
      ID=BrowseGallery1.Selected.ID
   ), 
   {Selected: "No"}
;)
Refresh('Associate Consultants');
UpdateContext({vCheck:false})

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

Awesome! At least I'm not being totally dumb! 🙂

 

I'll give this a try and come back to you...

Hi @WarrenBelz ,

 

Definitely some weird stuff going on there. Still not working quite as I'd hoped though. I would have thought this would be a pretty simple thing. Change toggle -> Update Data Source... The End. I can't see why it's changing back - even though we've change the default behaviour to cover any screen / page refreshing.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,253)