on 08-12-2012 8:05 AM
Hi guys,
I have a DropdownBox with just one item. SAPUI5 selects this item by default, but doesn't fire event and hence the model behind is not updated. This is probably a bug that needs to be fixed.
However, on form submit, I want to simulate such event, but it looks hard to me to get the selected item, because there's no such method getSlectedItem(). There is getSelectedKey(), getSelectedItemId(), getItems(), but not getSelectedItem(). The only way that comes to my mind is to get the selected key, iterate through all the items and find the one with the given key.
My question is is there any simpler way to get the selected item? And since I need this to fire a change event, which in turn will probably update the model, is there already a function which I can call to force an UI control to update the model property, which it is bound to.
Best Regards
Ivan
Hi Ivan,
use oDropdownBox.getLiveValue();
it works 100%
Regards,
Bheki
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi!
Have you try this on jQuery:
$("DropdownBox1").val();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok.
Is a dropdownbox right?
I think you might have to combine some methods:
mydropdownbox.getSelectedItemId(): for catch the Id of the selectec item.
mydropdownbox.getItems(): it returns a sap.ui.core.ListItem[] (an array) and with the Id you get the selected element from the array.
I hope this can help you.
Hi Raul,
What you suggested will probably work. My question was if there is already a method I can call. Here it is:
The only way that comes to my mind is to get the selected key, iterate through all the items and find the one with the given key.
My question is is there any simpler way to get the selected item?
However, I already found another solution which I find pretty acceptable, so I don't need to get the selected item anymore.
Ivan
Hy Ivan nevertheless you could try out the oModel.getProperty("<FieldName>", context); Method...
I use it working with a table where i get the selectedRowContext as parameter from the eventhandler ( event.getParameter("<>")) but its hard to find out which parameter are given, for dropdownBox for example the "newValue" parameter....
greetz
Hello Ivan,
have you found out how to fire events from DropdownBox meanwhile ?
Thanks for reply.
Greetings Chris
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ok i`ve found out how to get an event from dropdownBox.
you can use the change event from sap.ui.commons.TextField
var cockpitDropdown = new sap.ui.commons.DropdownBox(this.createId("cockpitDropDown"),{
searchHelpEnabled: true,
change: oController.doSomething
});
next question to solve is how get the Index from selected Item.
Hi Christoph,
I solved my problem using different approach. I added one empty item in the beginning, so the user should select the option manually. On manual selection the appropriate event gets fired.
oDictDetails.oCbTargetLang = new sap.ui.commons.DropdownBox('cb-dict-targetlang', {
value: "{/targetlang}",
editable:false,
selectedKey:undefined,
selectedItemId:undefined,
items: [
new sap.ui.core.ListItem({text: "", key: undefined}),
new sap.ui.core.ListItem("German",{text: "German", key: "de"})
]
});
Greetings
Ivan
User | Count |
---|---|
78 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.