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

OnChange not triggering for dropdowns

I have a PowerApp that connects to a SharePoint list.

The form has two dropdowns that get data from another list, such that the items in the second dropdown as filtered based on the selection in the first one.

 

Based on the selection in the second dropdown, I need to populate a textbox.

 

The form works fine when I am creating a new record.

 

However, when I open an existing record, the OnChange of the dropdowns do not work.

The OnChange of the first dropdown has Reset for the second dropdown and the textbox.

The OnChange of the second dropdown has code to get data for the textbox, and set it to a variable.

 

What could be the issue here?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User II
Super User II

Nope. Set the datepicker default property to Dropdown2.Selected.ElectionsDate and the textbox default property to Dropdown2. Selected.population. A dropdown control shows only one field in the window but all the fields in the entire record selected can be referenced. 

View solution in original post

7 REPLIES 7
Super User II
Super User II

Hi @rohinMVP 

Generally, you don't need to use a reset or OnChange property of a dependent dropdown.  Simply set the Items property of the dropdown to filter based on the primary dropdown.  So for example, you might want a dropdown that shows cities based on states selected in the primary dropdown.  Then you would have 

Filter(spList, state=Dropdown1.Selected.state) and show cities in the window of dropdown2. 

@Drrickrypgoing by your example, once I select the city, I want to see the current population in a text box, and the date of last election in a datepicker.

 

Wouldn't I need the OnChange for that?

Super User II
Super User II

Nope. Set the datepicker default property to Dropdown2.Selected.ElectionsDate and the textbox default property to Dropdown2. Selected.population. A dropdown control shows only one field in the window but all the fields in the entire record selected can be referenced. 

View solution in original post

Helper III
Helper III

My first dropdown has  Items set as 'Sort(Distinct(MyList.'State','State'),Result)', as I wanted to show unique items.

 

The second dropdown has Items set as ' Filter(MyList, State=ComboBox1.Selected.Result).'City''

 

I cannot get the textbox and datepicker values as you have mentioned.

Hi @rohinMVP ,

As you have requested on your other post, I have looked at this for you.

From what I see, you need one small change and then follow @Drrickryp 's guidance - change the Items of the second Combo Box to this

Filter(
   MyList, 
   State=ComboBox1.Selected.Result
)

then select the combo box and go into the Edit as below

cbValues.png

I have assumed the field names here, but the DefaultDate of your Date Picker will be

ComboBox2.Selected.ElectionDate

and the Default of your Text Box

ComboBox2.Selected.Population

You may have to reset these on the OnChange of the Combo Box (as you have mentioned) and the reason for the change is that previously, your Items were only one field - now it is a table that can be referenced as above.

 

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.

 

 

Helper III
Helper III

@WarrenBelz,

That helped me to get the textbox and datepicker values without OnChange.

However, the data doesn't persist on opening the existing record.

 

In the second combobox I have these now:

Default:{Result:ThisItem.'City'}

DefaultSelectedItems:{Result:ThisItem.'City'}

Items:Filter(MyList, State=ComboBox1.Selected.Result)

OnChange: false

 

  • How can I persist the data here?
  • Is it possible to clear the second combobox and the other controls on change of first combobox?

@rohinMVP ,

I will pass this back to @Drrickryp as I only responded here on your request and answered the specific question you were asking.

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Top Solution Authors
Top Kudoed Authors
Users online (43,634)