470
Views
2
Comments
Solved
What is the correct way to model OnKeyDown?
Application Type
Reactive
Service Studio Version
11.51.4 (Build 57443)

Hello,

I'm trying to modify a search field to only trigger an API call OnKeyDown === 'Enter' instead of OnChange. It works with "return event.key === 'Enter'", but since that is deprecated I'm looking for the correct field to specify in js using the OutSystems API.

Thanks!

2021-03-18 21-03-15
Benjith Sam
 
MVP
Solution

Hi Ryan,

For the mentioned use case you can try the below JS: 

var searchInpt = document.getElementById($parameters.SearchInputId);

searchInpt.addEventListener('keypress', function (e) {
    var code = e.keyCode || e.which || e.charCode;
    if(code === 13) { //Enter keycode
        $actions.SearchFruitByFruitName();
    }
});

See this sample SearchInputDemo

Refer to the attached .oml file.


I hope this helps you!


Kind regards,

Benjith Sam

RWA_Lab_SearchInput.oml
UserImage.jpg
Ryan Saunderson

Thanks @Benjith Sam 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.