I have a lightning component that contains an input like this :
<ui:inputText aura:id="searchTerm" class="form-control" placeholder="..." keyup="{!c.rechercher}" />
I want that the logic of my JS method is started when the user press the "enter" button, so I did that :
rechercher : function(component, event, helper){
var j$ = jQuery.noConflict();
var searchTerm = component.find('searchTerm');
var jSearchTerm = j$(searchTerm.getElement());
component.set('v.searchTerm', jSearchTerm.val());
if(event.getParams().keyCode == 13 ){
var action = component.get("c.getSearchKnowledgeArticles");
action.setParams({
'searchTerm' : jSearchTerm.val()
});
action.setCallback(this, function(a) {
var state = a.getState();
console.log('### state : ' + state);
if (state === "SUCCESS"){
var result = a.getReturnValue();
component.set('v.searchResults', result);
var nbResult = result.length;
console.log('nbResult : ' + nbResult);
component.set('v.nbResult', nbResult);
}
});
$A.enqueueAction(action);
}
}
But when I ty this I got the error : "searchTerm.getElement is not a function"
But if I try to change the tag in the component like that :
<input type="text" id="search" aura:id="searchTerm" class="form-control" placeholder="..." onkeyup="{!c.rechercher}" />
Then I got the error : "event.getParams is not a function"