on 2024 Apr 19 9:50 PM
Hi.
How to execute fire onPost when user press enter on FeedInput element of SAP UI5? I need that when the user press enter in FeedInput element in SAP fiori the system behaves as when the user click on post button.
Thanks and best regards.
Request clarification before answering.
The FeedInput component naturally inserts a new line when you press Enter. I wouldn't suggest changing this default behavior, however if your application still requires onFocus to be fired when enter is pressed on input area, here's how it can be achived:
Add this onAfterRendering method to your View Controller:
onAfterRendering : function () {
//note: replace 'myFeedInputID' with ID of FeedInput component
let myFeedInput = this.byId('myFeedInputID');
let dom = myFeedInput.getFocusDomRef();
if (dom) {
dom.addEventListener('keypress', (evt) => {
if ((evt.keyCode || evt.which) == 13) {
if (evt.preventDefault)
evt.preventDefault();
myFeedInput.firePost();
// you can also call your custom code directly here (instead of firing post event)
}
});
}
},
Note that the provided code should be executed only after the FeedInput component has been rendered. To ensure this, I've wrapped the code inside the onAfterRendering method of the view controller.
Please upvote if this helps. Thanks!
- Sajid Khan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
12 | |
9 | |
8 | |
8 | |
5 | |
4 | |
4 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.