I am tryin to handle field validation for a lightning:input field in a custom aura component. I've referenced the validating fields documentation with no success. I find my lightning:input component in my JS controller, pull it's value, but when i try to conditionally set the error message, I get an error:
Uncaught Action Failed... [Cannot read property 'config' of undefined]"
Here's my component markup:
<aura:component controller="cntrler" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" description="desc" access="global" >
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<aura:attribute name="savedSearchSelected" type="Boolean" default="true" description="Tracks whether the user is filtering a saved search or performing a new search" />
<aura:renderIf isTrue="{!v.savedSearchSelected == false}">
<div class="slds-size_1-of-1">
<div class="slds-m-around_x-small">
<lightning:input name="search-name" value="{!v.savedSearchName}" placeholder="Name your search, if you'd like" aura:id="search-name"/>
</div>
</div>
</aura:renderIf>
</aura:component>
Javascript Controller
({
saveSearch : function(component, event, helper) {
var input = component.find('search-name');
var searchName = input.get('v.value')
console.log(input, searchName);
if(helper.isEmpty(searchName)){
console.log('empty name');
//input.set('v.errors',[{message:'Please name your search before saving'}]);
} else {
//input.set('v.errors', null);
}
}
})
The input.set() lines in the controller are what's causing the error. Why am I not able to use this component.set() method when I am successfully retrieving the component (as shown by my console.log and even the .get value from that component in the line prior)
input.get('v.value')
? I doubt if that's the one. Is this your exact code? E.g., I seecontroller="cntrlr.cls"
, which is syntactically incorrect and I think won't let you save the component.//input.set('v.errors',[{message:'Please name your search before saving'}]);
and//input.set('v.errors', null);
input.get
butinput.set
, right?