2

I want to trigger controller method only when text box gets cleared out. I tried to use IF condition in onchange but it throws out error Uncaught Uncaught error in markup://aura:valueChange [Cannot read property 'config' of undefined]

<lightning:input type="text" name="searchBox" label="{!v.searchLabel}" 
 value ="{!v.searchString}" onchange ="{!if(v.searchString == null,c.onEmptyInput,''}"/>

I know I can just use onchange={!c.onEmptyInput} and then check if searchString is null in controller method and write my logic based on that. But I want to know if IF statements can be used to call controller methods.

3

I know I can just use onchange={!c.onEmptyInput} and then check if searchString is null in controller method and write my logic based on that.

You should stick to this approach instead of using any conditional logic here. Additionally, your onchange will not even trigger if the input is empty.

With what you are trying to do, you won't be able to use a conditional statement here, as it will not work. For onchange to work, you will need to explicitly mention a controller function in format of:

onchange="{!c.myFunction}"

Values anything other than this format will have no effect on the event handler (I can confirm this with a quick test). In this case even if your if condition evaluates correctly (this is not correctly written though in its current form and you will get a compile time error), you will only get a value, which will not be of the same format as what is expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.