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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / OnChange causing bug -...
Power Apps
Answered

OnChange causing bug - I have to double click before entering information into text input field

(1) ShareShare
ReportReport
Posted on by 28

Hello,

 

I have a Gallery, it's data source is a collection. Inside the gallery I have multiple text input fields and OnChange of the input fields I collect the text into the collection. The Default property of the text input fields is ThisItem.nameOfCollectionItem.

 

Everything works as it should and my collection is being updated as it should, but since the update happens on 'OnChange', after I enter text then click on an other input field, it unselects and I need to click again.

 

I need to either double click after making a change, or click on white space first then the next text input field

 

Here's a video of my issue:

ezgif.com-gif-maker.gif

Here's my OnChange code :

sam_646_1-1659540064899.png

 

Here's my Default code:

sam_646_2-1659540087291.png

 

Categories:
I have the same question (0)
  • Verified answer
    Scott_Parker Profile Picture
    1,090 on at

    I can reproduce your issue. It looks unavoidable if using a single gallery and updating OnChange. There is a solution to get what you want, but is a bit more work.

     

    Roughly what is causing the issue is this sequence of events:

     

    1. Select first control and make changes
    2. Select the next control and OnChange fires for the first control
    3. OnChange runs, updating the data source for current item in the gallery.
    4. Because the data source of the current item changed, all the controls for the current item refresh. Including the one you just selected.
    5. This control refresh causes the controls to become unselected, causing what you're observing as needing to double-click

     

    You will notice that if you select a control on a different item in the gallery, you won't have this unselect issue, because the control you just selected wasn't refreshed.

     

    Two options of the top of my head:

    1. Use a save button to update the collection after all changes are made. Not quite a clean as OnChange handling the updates.
    2. (overkill, but will do what you want) Create a separate gallery for each field you want input for. Set the data source for each gallery to:

     

    ShowColumns(colExample, "ID", "Value")

     

    Where you replace "Value" with the control you're adding to that gallery. So, you would have 3 separate galleries, each with a text input control having OnChange along the lines of:

     

    UpdateIf(colExample, ThisItem.ID = ID,{Value:TextInput1})

     

     

  • sam_646 Profile Picture
    28 on at

    Hi Scott, thank you for the help - I managed to get it working with a save button in that place; 

    However, I'm trying to do the same but in a Gallery with repeating tables.

     

    Essentially I am trying to loop through all items the Gallery and update the collection for each item, when the '+ Add New Row' button is clicked, the collection is populated with a new empty row, and I want the save button to update those empty fields with the data in the Gallery. I believe it's a problem with my code, I would be grateful if you can assist 🙂

     

    Gallery view:

    sam_646_0-1659625712063.png

     

    With another row:

    sam_646_1-1659625846887.png

     

     

     

    + Add New Row Code:

    Collect(
     colAnyIssuesPreventingDeliveryUpdates,
     {
     FormReference: varFormReferenceNumber,
     Date: Today(),
     Time: varTimeOnAppStart,
     Description: "",
     IssueType: ""
     }
    )

     

    Save button code:

    ForAll(
     'Any Issues Preventing Delivery Gallery'.AllItems,
     Update(
     colAnyIssuesPreventingDeliveryUpdates,
     LookUp(
     colAnyIssuesPreventingDeliveryUpdates,
     ThisRecord.Description = ThisRecord.Description
     ),
     {
     FormReference: FormIDFromVar,
     IssueType: IssueTypeInput.Selected.Value,
     Description: DescriptionInput.Text,
     Date: DateInput.SelectedDate,
     Time: TimeInput.Text
     }
     )
    )

     

    The save button works as it should if there is only 1 row in the gallery, when I add a new row in the gallery and click save it doesn't work as expected 🙂

     

  • Scott_Parker Profile Picture
    1,090 on at

    Your save button has this line of code

    ThisRecord.Description = ThisRecord.Description

    This will always be true, so your LookUp is always returning the first item.

     

    You probably meant to write:

    Description = ThisRecord.Description

     

     

  • sam_646 Profile Picture
    28 on at

    Better than what it was yesterday but unfortunately I still can't get it to work.

     

    My Gallery when I add 3 new rows:

    sam_646_1-1659684879740.png

     

    My collection when I add 3 new rows (the Form Reference, Date and Time are automatically "assigned"):

    sam_646_0-1659684785639.png

     

    Gallery with data before I click save:

    sam_646_2-1659684957490.png

     

    My Gallery after I click save (the first row has changed to match the last row, but the middle row remained the same):

    sam_646_3-1659684980191.png

     

    My collection after clicking save:

    sam_646_4-1659685025439.png

     

     

    My Save button code:

    ForAll(
     'Any Issues Preventing Delivery Gallery'.AllItems,
     Update(
     colAnyIssuesPreventingDeliveryUpdates,
     LookUp(
     colAnyIssuesPreventingDeliveryUpdates,
     Description = ThisRecord.Description
     ),
     {
     FormReference: FormIDFromVar,
     IssueType: IssueTypeInput.Selected.Value,
     Description: DescriptionInput.Text,
     Date: DateInput.SelectedDate,
     Time: TimeInput.Text
     }
     )
    )

     

    I would greatly appreciate any help

     

     

     

     

     

     

  • Scott_Parker Profile Picture
    1,090 on at

    It's because you're using Description like it is an ID field. For your LookUp, make a comparison on an ID column (or another primary key candidate column)

    ID = ThisRecord.ID

    Because your description are initially all blank, it was still returning the first row in the LookUp.

  • sam_646 Profile Picture
    28 on at

    The same sort of thing happens, this is my new code:

    ForAll(
     'Any Issues Preventing Delivery Gallery'.AllItems,
     Update(
     colAnyIssuesPreventingDeliveryUpdates,
     LookUp(
     colAnyIssuesPreventingDeliveryUpdates,
     Description = ThisRecord.Description
     ),
     {
     FormReference: FormIDFromVar,
     IssueType: IssueTypeInput.Selected.Value,
     Description: DescriptionInput.Text,
     Date: DateInput.SelectedDate,
     Time: TimeInput.Text
     }
     )
    )

     

    My gallery before I click save:

    sam_646_0-1659946532904.png

     

     

    My Gallery after I click save:

    sam_646_1-1659946555337.png

     

     

    My collection after I click save:

    sam_646_2-1659946571308.png

     

     

     

  • Scott_Parker Profile Picture
    1,090 on at

    Your old code looks identical to your previous code.

  • sam_646 Profile Picture
    28 on at

    Thank you for your reply,

     

    I changed this line from:

    ThisRecord.Description = ThisRecord.Description

     

    To:

    Description = ThisRecord.Description
  • sam_646 Profile Picture
    28 on at

    My apologies, I didn't see your reply

    "

    It's because you're using Description like it is an ID field. For your LookUp, make a comparison on an ID column (or another primary key candidate column)

    ID = ThisRecord.ID

    Because your description are initially all blank, it was still returning the first row in the LookUp.

     

    Sorry about that

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 85

#2
WarrenBelz Profile Picture

WarrenBelz 76 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 38 Super User 2026 Season 1

Last 30 days Overall leaderboard