Skip to Content
1
Jun 20, 2022 at 02:27 PM

SAPUI5 Focus the Search Field inside Select Dialog

783 Views Last edit Jun 20, 2022 at 05:33 PM 2 rev

Hello everyone,

In the Fiori / SAPUI5 app, which I am currently expanding, I use several value helps in the form of select dialogs. I would like to have the search field within the select dialog to be focused after opening the select dialog fragment with .open() in the JavaScript controller.

At the moment it is only focused for a short time until the data for the value help is loaded. Then it automatically loses focus again. So far I haven't been able to fix the problem with .focus(). Also not in connection with addEventDelegate and the events onAfterRendering or onkeydown.

The same problem occurs with the official Select Dialog samples: https://sapui5.hana.ondemand.com/#/entity/sap.m.SelectDialog/sample/sap.m.sample.SelectDialog

Thanks in advance for all the ideas and suggested solutions.

Max

Here's the code snippet used to invoke the Select Dialog:

this.valueHelpCustomer = sap.ui.xmlfragment("cus.crm.mytickets.ZCRM_MYTICKETSExtensionV3.view.ValueHelpCustomer", this);
this.valueHelpCustomer.bindAggregation("items", {
		            path: "/CustomerCollection",
		            sorter: [new sap.ui.model.Sorter("employeeID", false, function (C) {})],
		            template: this.valueHelpCustomer.getItems()[0].clone()
});
this.valueHelpCustomer.setModel(this.getView().getModel());
this.valueHelpCustomer.setModel(this.getView().getModel("i18n"), "i18n");
this.valueHelpCustomer.open();<br>