I have a lightning:input
and when the focus is on it and you type the enter stroke: it refreshes the page.
I tried to prevent it by implementing the onchange
: avoid the event to be fire but the callback is never launched.
Component.cmp:
<lightning:input
type="email"
onchange="{! c.callbackNeverCalled }"
/>
Controller.js:
callbackNeverCalled: function(component, event, helper) {
event.preventDefault(); // Does not prevent from refreshing/redirecting the page & also 'deprecated'.
event.getSource().getParams();
// Is an empty object but the good way to do (cf. documentation)
}
onchange
event is now working. But there are still two issues:event.preventDefault()
do not prevent from refreshing/redirecting the page and I can access the keyup by doingevent.getSource().getElement().KEYUP
(this will be deprecated, displayed at usage forevent.getSource().getParams()
but this does not return anything other than an empty object at the moment).event.KEYUP
give us this message:Avoid relying on the native event attribute KEYUP as it is only included for backwards-compatibility. It will eventually be deprecated. Use the aura event API (e.g., getSource(), getParams(), etc) instead.