cancel
Showing results for 
Search instead for 
Did you mean: 

reset dropdown on change of value in other dropdown

Former Member
0 Kudos

Hi.I have two dropdowns.First has its values as select,A,B and C.Second dropdown has its values as select,D,E and F.When I change the value of first dropdown,second dropdown get visible.Now when I again change the first dropdown's value second dropdown gets visible with the previos value.But I want to reset the second dropdown to "select" whenever I change the value in first dropdown.Whant can be the possible solution?
.

Accepted Solutions (1)

Accepted Solutions (1)

antonette_oberholster
Active Contributor
0 Kudos

Hallo Bhawna

Look at this:

"setSelectedItemId(sSelectedItemId)

Setter for property selectedItemId.

Default value is undefined."

According to API doc the default value for dropdown is "undefined".

So in you first dropdown, set your second dropdown to "undefined" by trying something like this:

dropdown2.setSelectedItemId(undefined); (or maybe use ("undefined"))

Haven't tried it myself, but worth a shot

Regards

Antonette

antonette_oberholster
Active Contributor
0 Kudos

You can also try it for .setSelectedKey()

antonette_oberholster
Active Contributor
0 Kudos

Unless "select" is an actual item in your dropdown, in that case you can just do:

dropdown2.setSelectedKey("select");

or

dropdown2.setValue("select");

Former Member
0 Kudos

Thanks for your response but I tried,its not working

seVladimirs
Active Contributor
0 Kudos

Can you share your code?

Answers (3)

Answers (3)

Former Member
0 Kudos

Thanks.SetValue worked.One more issue.What if I am getting values in a dropdown from backend and I want to append hardcoded "select" in it.What Can I do in that case

antonette_oberholster
Active Contributor
0 Kudos

I'm glad it works

not sure, I'll check, but I think you might have to open a new thread for that so others can help

Regads

Antonette

agentry_src
Active Contributor
0 Kudos

Yes, please open a new Discussion and mark Correct and Helpful Answers to this one so others can benefit from the solution.

Regards, Mike (Moderator)

SAP Technology RIG

antonette_oberholster
Active Contributor
0 Kudos

Hey Bhawna

Use console to show exactly when the values change/should change and when your events start firing. It sounds as if your chaining is not right,

"Now when I again change the first dropdown's value second dropdown gets visible with the previos value"

This usually happens when your setSelectedKey fires before you have finished determining what the value should be, that is why you see the previous value.

Regards

Antonette

Former Member
0 Kudos

Hi Bhawna,

The possible solution is that you have to user "firechange" event of your drop down 2.

Check the below code. Where I am resetting my dropdown using firechange event.

var r = this.byId("idSelectWeek");

r.fireChange(this.byId("idSelectWeek").getSelectedItem());

Please make suitable adjustments to your code and incorporate the event functionality.

Hope this will help you.

Regards

Abhijeet

Former Member
0 Kudos

what is idSelectWeek in this example

Former Member
0 Kudos

"idSelectWeek" is id of my dropdown control. You need to replace it with id of your control.

Moreover, fireChange event will only work if you have defined "Change" event of your control.

XML Code:

localDataModel is my oData model name (it's optional). Change event will be fired using "fireChange" in code. Change event will contain your logic to reset.

<Select id="idSelectWeek" width="10em" change="onSelectWeekChange"

     autoAdjustWidth="true" items="{localDataModel>/Weeks}" selectedKey="0">

     <core:Item key="{localDataModel>id}" text="{localDataModel>text}" />

  </Select>

onSelectWeekChange : function(oEvent)

  {

  

    selfView = this;

    var r = selfView.byId("idSelectWeek");

    var selectedItem = r.getItemByKey(selfView.byId("idSelectWeek").getSelectedKey());

    var selectedDesc = selfView.byId("idSelectWeek").getSelectedKey();

}

Trigger "Change" event to reset your dropdown 2 using below code. This code will most probably be written in your dropdown 1 onChange event

      var r = selfView.byId("idSelectWeek");

      r.fireChange(selfView.byId("idSelectWeek").getSelectedItem());

Regards,

Abhijeet