cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

dependent combobox, element binding, set default element

Koen_VL
Participant
0 Likes
1,434

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

Accepted Solutions (1)

Accepted Solutions (1)

maheshpalavalli
Active Contributor

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

WouterLemaire
SAP Mentor
SAP Mentor

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.

Answers (1)

Answers (1)

venkateswaran_k
Active Contributor
0 Likes

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