Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

OnChange issue - double clicking action to set focus on fields within a Gallery



I'm a newbie and this is my first post so apologies in advanced.


We have an issue with a set of fields within a gallery (which has a collection data source):



We have an issue whereby for each of the input text fields shown above we have to clicking twice on the field before we can enter in any data.


The “double” clicking action to set focus in one of the text inputs comes about we believe because the input text fields have an OnChange action:


If(!IsBlank(NameColInput.Text)     && NameColInput.Text     <> ""  &&

   !IsBlank(CompanyColInput.Text)  && CompanyColInput.Text  <> ""  &&

   !IsBlank(PositionColInput.Text) && PositionColInput.Text <> "",

   Set(varValidRow, true),

   Set(varValidRow, false));





     {IDCol:       ThisItem.IDCol,

      NameCol:     NameColInput.Text,

      CompanyCol:  CompanyColInput.Text,

      PositionCol: PositionColInput.Text,

      ValidRow:    varValidRow}



We thought about moving the functionality for saving the entered collection data to the submit button at the end of the process.

This seemed like a better place for it anyway. However, we came across other issue with the Gallery.AllItems value being null.


What we thought about using on Submit was a ForAll loop to go through the Gallery.AllItems and patch the collection.

However, this didn’t work because the AllItems was always returning null (is this a bug?).


To get around the Allitems issue, we also thought about swapping in the collection and out for the Gallery.AllItems but you can’t loop through and update the same collection within a ForAll loop:



    Notify("[" & IDColInput.Text & "]");

    Patch(RecipientsCollection, LookUp(RecipientsCollection, IDCol = Value(IDColInput.Text)),

     {IDCol:       Value(IDColInput.Text),

      NameCol:     NameColInput.Text,

      CompanyCol:  CompanyColInput.Text,

      PositionCol: PositionColInput.Text})


So we've hit a blank now and we don't know what to try next - does anyone have any ideas?




Kudo Kingpin
Kudo Kingpin

Re: OnChange issue - double clicking action to set focus on fields within a Gallery

Hi Adrian,

well, in general, any kind of self reference in onchange can cause such awkward behavior. 

I would start by checking when the error disappears by removing parts of the function.
As soon as you find it the next step will be to check what and why cause the error and try to find another approach.
So, for example, I would delete OnChange action content. If it helps, then the question is whether it can be put elsewhere. Maybe you can give a label / warning that appears if these fields values are empty - so the checking operation would not happen in onchange action. Especially that the OnChange approach is imperative, and powerapps was created to work in declarative approach.

Frequent Visitor

Re: OnChange issue - double clicking action to set focus on fields within a Gallery

Hi Mike,


Thanks for the reply, I know that the Update() is causing the issue.

I did try and move the code out of the OnChange, that's what the error checking above it was for (by setting the varValidRow).


My plan was to check all varValidRow values where true. If they were, I would Update()/Patch() the record(s), otherwise I would show an error message.


What I couldn't figure out was how to do the Update outside of the Gallery, do you have any suggestions?

As I mentioned the Gallery.AllItems didn't work.




Kudo Kingpin
Kudo Kingpin

Re: OnChange issue - double clicking action to set focus on fields within a Gallery

1. User a collection and just display it using gallery. So in that case you'll need to work on the collection, not gallery.
2. Instead If before Update you can run UpdateIf function

3. Nevetherelss a function ForlAll(Gallery.AllItems) should work properly anyway. Especially with Patch/Update in it. I use it quite frequently 🙂 Just make sure you reference to the proper items inside forall and patch function - sometimes I've got confused when the names where to similar to each other (control name, column name, record name)

Helpful resources

Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.


Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (6,732)