web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / OnChange issue - doubl...
Power Apps
Unanswered

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

(0) ShareShare
ReportReport
Posted on by

Hello,

 

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):

 

sample1.jpg

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));

  

Update(RecipientsCollection,

     LookUp(RecipientsCollection,IDCol=ThisItem.IDCol),

 

     {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:

ForAll(

    RecipientsCollection,

    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?

 

Thanks

Adrian

Categories:
I have the same question (3)
  • Mike_Guzowski Profile Picture
    219 on at

    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.

  • Community Power Platform Member Profile Picture
    on at

    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.

     

    Cheers

    Adrian

  • Mike_Guzowski Profile Picture
    219 on at

    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)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard