on 07-29-2015 6:58 AM
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?
.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"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
User | Count |
---|---|
96 | |
11 | |
11 | |
10 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.