on ‎2020 May 15 8:19 PM
Hello,
I have defined 2 dependent comboBoxes and implemented element binding to accommodate the master-detail relationship in the binding between both. the code is below and it is working fine. The code is below.
I can however not find a way to set a default value in the second (dependent-detail) combobox. I would like to set the first item of the binded list as a default there.
<****************** view.xml *************>
<ComboBox id="comboSystemID" items="{/SystemSet}" selectionChange="onSystemSelected">
<core:Item key="{SystemId}" text="{SystemId}"/>
</ComboBox>
<ComboBox id="clientID" items="{ClientSet}">
<core:Item key="{ClientId}" text="{ClientId}"/>
</ComboBox>
<****************** controller.js *************>
onSystemSelected: function (oEvent) {
var sPath = sap.ui.getCore().byId(oEvent.getSource().getSelectedItemId()).getBindingContext().getPath();
var oClientID = this.byId("clientID");
oClientID.bindElement({ path: sPath });
// ---> how can I set here a default value based from the binding?
}
Any ideas?
thanks
Koen
Request clarification before answering.
Hi koen.vanloocke2
Simple way is the use sap.m.Select which has the property "forceSelection", if you set it, automatically the first item will be selected.
if you still want to do it using combobox then you need to attach event for "dataReceived" like shown in the below question and read the data and set the default selectedKey to the combobox
https://answers.sap.com/questions/11617993/event-when-binding-sapmselect-is-done.html
-Mahesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Selectedkey could also be bound to one of the properties in the entity used in the bindeElement assuming that you use an association in the second dropdown for items and you have the selected key in the properties of the entity that you bind.
Hi
Try this code - on before rendering ;
onBeforeRendering: function() {
console.log(this.getView().byId("SystemID").getSelectedKey());
var sPath = this.getView().byId("combobox_id").getBindingContext().getPath();
var oClientID = this.byId("clientID");
oClientID.bindElement({ path: sPath });
}
Regards,
Venkat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 8 | |
| 8 | |
| 7 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.