Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: Missing parameter in API sap.m.ListBase -> setSelectedItem #3367

Closed
iljapostnovs opened this issue Oct 12, 2021 · 12 comments
Closed

Comments

@iljapostnovs
Copy link

There are three parameters for setSelectedItem in sap.m.ListBase:
image

However, bFireEvent parameter is absent in JSDoc and in API as well.

@Shtilianova
Copy link
Contributor

Hello @iljapostnovs,
Thank you for sharing your enhancement proposal. I've created an internal incident 2170255951. The status of the issue will be updated here in GitHub.
Regards, Diana

@jaybarbhaiya
Copy link
Contributor

Hi @iljapostnovs ,
This is done intentionally, The bFireEvent paramter is used by the ListBase internally and we did not want to make this parameter public. The JSDoc was hence not provided since we wanted to not show this parameter in our API documentation.
Best regards,
Jay

@iljapostnovs
Copy link
Author

Hi @jaybarbhaiya,
It's a pity that it's for internal usage, because it makes a lot of sense for us as well.
Let's take an example:
Let's imagine I want to implement auto selection of first item if there is only one item in the list.
How can I do it?

oList.attachUpdateFinished(() => {
  if (oList.getItems().length === 1) {
    const oFirstItem = oList.getItems()[0];
   //what happens next? How to select first item?
   //It is possible to use setSelectedItem, but it doesn't fire event
   //oList.fireSelectionChange can't be fired, because it's a protected method of class sap.m.ListBase
  //setSelectedItem has third parameter which is responsible for firing the event, which officially we can't use because it's for internal usage
  }
});

So officially the only way to fire selectionChange event together with selection is to extend e.g. sap.m.List, add custom method, like setSelectedItemAndFireEvent, and use setSelectedItem and fireSelectionChange from there. A bit a long way for such a simple task. Maybe you would consider to make this third param public? :)

@jaybarbhaiya
Copy link
Contributor

Hi @iljapostnovs ,

We would require more details on the requirement and the application scenario. The selectionChange event is only fired for user interaction. If you have some special handling on selection of the first item in the List and you want to trigger the selectionChange event after selection the first item programmatically, then you can also call the fireSelectionChange() which is a public function. This will fire the event and your corresponding event handler will also be triggered.

Alternatively you can also perform the selection and trigger a call to your selectionChange handler after you have selected the item in the list.

Thank you.
Best regards,
Jay

@iljapostnovs
Copy link
Author

iljapostnovs commented Oct 14, 2021

Hi @iljapostnovs ,

We would require more details on the requirement and the application scenario. The selectionChange event is only fired for user interaction. If you have some special handling on selection of the first item in the List and you want to trigger the selectionChange event after selection the first item programmatically, then you can also call the fireSelectionChange() which is a public function. This will fire the event and your corresponding event handler will also be triggered.

Alternatively you can also perform the selection and trigger a call to your selectionChange handler after you have selected the item in the list.

Thank you. Best regards, Jay

Hi,

fireSelectionChange is protected, not public, please see the api: https://ui5.sap.com/#/api/sap.m.ListBase%23methods/fireSelectionChange
image
Which basically means that I can't call it outside of the sap.m.List class/subclass

@jaybarbhaiya
Copy link
Contributor

Hi @iljapostnovs,
Thanks for correcting me, but as also mentioned you can call you handler function after the item selection
Thanks and regards.,
Jay

@iljapostnovs
Copy link
Author

Hi @iljapostnovs, Thanks for correcting me, but as also mentioned you can call you handler function after the item selection Thanks and regards., Jay

The only way to call the protected method is to extend sap.m.List (or any sap.m.ListBase) and call it from there. And that is exactly what I was talking about here:
image

@iljapostnovs
Copy link
Author

Please check what access level modifiers are:
https://en.wikipedia.org/wiki/Access_modifiers

According to OOP, access level modifier @Protected means, that you can use a class member only in itself or in subclasses.
I will repeat myself, that means that fireSelectionChange can't be called outside of sap.m.List or any other class which extends sap.m.List.

@iljapostnovs
Copy link
Author

This is an example what error you would receive using typescript:
image

@iljapostnovs
Copy link
Author

iljapostnovs commented Oct 14, 2021

I have checked typescript type definitions for SAPUI5 provided by SAP and there fireSelectionChange is indeed public, which means that typescript definitions are not the same as UI5 API. In this case I would propose to you to synchronise typescript definitions with UI5 API and make fire(EventName) public everywhere in UI5 API.

@aborjinik
Copy link
Contributor

@iljapostnovs in general API calls do not fire events. Like chancing the value of the HTMLInputElement does not fire the input event. Here we try to understand your requirement whether we are missing out something or not but we are stuck on firing the event.
Could you please share your selectionChange event handler?

@iljapostnovs
Copy link
Author

iljapostnovs commented Oct 15, 2021

@iljapostnovs in general API calls do not fire events. Like chancing the value of the HTMLInputElement does not fire the input event. Here we try to understand your requirement whether we are missing out something or not but we are stuck on firing the event. Could you please share your selectionChange event handler?

Hi,
I don't understand how your answer is related to the fact, that fireSelectionChange method is marked as protected?
I have no event handler to share, because the problem is not related to event handler.
The problem is that there is no official way to select item by code and fire selectionChange event without extending sap.m.List (or any other list). Please, if somebody doesn't know what "protected" means, delegate this issue to somebody who does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants