You need to sign in to do that
Don't have an account?
lightning:input events?
I'm seeking more info on lightning:input for use in a Lightning Component.
What I want to do is have the input text field submit when the user presses the Enter key. However, the Enter key seems to be ignored by lightning:input. Also, I can't even retrieve the keycode with my handler.
component markup:
BTW, I've tried doing this with ui:inputText as well, and that doesn't work either.
Help please?
What I want to do is have the input text field submit when the user presses the Enter key. However, the Enter key seems to be ignored by lightning:input. Also, I can't even retrieve the keycode with my handler.
component markup:
<lightning:input aura:id="body" label="" name="Body" placeholder="Enter message..." value="{!v.Message.Body__c}" onchange="{!c.keyCheck}"/> </lightning:layoutItem>And my keyCheck handler:
keyCheck: function(component, event, helper){ console.log(event.getParams('keyCode')); }The handler is getting called, but the value is undefined. I think it's undefined because the event that is happening is NOT the keypress/keyDown/keyUp, but rather the input field is changing. But lightning:input chokes (won't compile) if I try to add a keyDown event in its parameters in the markup.
BTW, I've tried doing this with ui:inputText as well, and that doesn't work either.
Help please?
And the handler: Note that since span isn't a lightning element, I had to use the slds class on it, rather than the simpler size attribute.
All Answers
There are only three actions "on":
- onblur Action The action triggered when the element releases focus.
- onchange Action The action triggered when a value attribute changes.
- onfocus Action The action triggered when the element receives focus.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_lightning_input.htm AlainI guess I'll venture outside of Lightning to general Javascript and try to find a window or document event sensor.
I tried this and that works.
Component:
Controller.js
Helper.js
http://https://salesforce.stackexchange.com/questions/189788/what-key-is-pressed-in-lightning-component/189796
And the handler: Note that since span isn't a lightning element, I had to use the slds class on it, rather than the simpler size attribute.
<div onkeyup="{! c.handleKeyUp }">
<lightning:input aura:id="enter-search" name="enter-search" label="Search when user hits the 'enter' key" type="search" />
</div>
</aura:component>
try this