function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Smitha Sirivolu 10Smitha Sirivolu 10 

How to activate the method onSubmit in < lightning:button onclick="{!c.onSubmit} /> when ENTER Key is Pressed

How to activate the method onSubmit in < lightning:button onclick="{!c.onSubmit} /> when ENTER Key is Pressed

in Aura components development
Ugur KayaUgur Kaya
Hi Smitha,

You can wrap your content (where you want to detect the key press) in a div and use onkeyup event. Check if the pressed key is `enter` and call submit.
Something similar to this:
<div onkeyup="{!c.handleKeyUp}">
...
...
...
</div>



handleKeyUp: function(component, event, helper){
        
        if (event.keyCode === 13) {
            //call submit
        }
        
}

 
Smitha Sirivolu 10Smitha Sirivolu 10
Works great !!! Thank you so much
Ugur KayaUgur Kaya
Perfect! Please kindly mark it as solved with the correct answer.