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
Dhiraj Gupta 1Dhiraj Gupta 1 

on change event is not getting fired

Hi Team,

When we type in search box then doSearch method of JS should be called but it's not happening.

Below is code:

Component code:

<aura:component >
     <aura:registerEvent name="BeerEvent" type="c:SearchEvents"/>
    <div class="slds-p-around_small">
      <lightning:input
        name="inline-search-input"
        label="Beer Search"
        type="search"
        variant="label-hidden"
       aura:id="searachInput"
       onChange="{!c.doSearch}"
    />
    </div>
</aura:component>

JS Code:
({
    doSearch : function(component, event, helper) {
        var componentEvents=component.getEvents('BeerEvent');
        var searchParam=componenet.find('searachInput').get('v.value');
        alert(searchParam);
        componentEvent.setParams({
            searchText:searchParam       
        });
        component.fire();
    }
})
Best Answer chosen by Dhiraj Gupta 1
David Zhu 🔥David Zhu 🔥
@Dhiraj. Good to hear that. Can you please mark my reply as the best answer?

All Answers

David Zhu 🔥David Zhu 🔥
You may need to use onchange instead of onChange.
onchange="{!c.doSearch}"
Agustin BAgustin B
Are you getting anything on the alert? I am seeing an error on the spelling of component
        var searchParam=componenet.find('searachInput').get('v.value');

if it helps please mark as correct, it may help others.
Dhiraj Gupta 1Dhiraj Gupta 1
Thanks, David.

It worked.
David Zhu 🔥David Zhu 🔥
@Dhiraj. Good to hear that. Can you please mark my reply as the best answer?
This was selected as the best answer
Dhiraj Gupta 1Dhiraj Gupta 1
Hi David,

I have one more query:
I am calling construtor but while debugging i am getting below error and cursor is not going inside setCallback method. It seems it is not calling apex class. Below is code:

({
    handleCompEvents : function(component, event, helper) {
        var searchParam=event.getParam('searchText');
        var action=component.get('search');
        action.setParams({
            txtSearch:searchParam
        });
        
        action.setCallback(this,function(response){
            var state=response.getState();
            if(state=='SUCCESS')
            {
                var responseValue=response.getReturnValue();
                console.log('responseValue',responseValue);
            }
        })
    }
})

Kindly help.
 
David Zhu 🔥David Zhu 🔥
You forgot enqueue the action.

({
    handleCompEvents : function(component, event, helper) {
        var searchParam=event.getParam('searchText');
        var action=component.get('search');
        action.setParams({
            txtSearch:searchParam
        });
        
        action.setCallback(this,function(response){
            var state=response.getState();
            if(state=='SUCCESS')
            {
                var responseValue=response.getReturnValue();
                console.log('responseValue',responseValue);
            }
        })
            $A.enqueueAction(action);
    }

})