You need to sign in to do that
Don't have an account?
Manish Kumar 344
How can solve this error"This page has an error. You might just need to refresh it. Unable to find 'Search' on 'compound://c.searchAccount1'. Failing descriptor: {markup://c:searchAccount1}"
searchAccountHelper.js
({
SearchHelper: function(component, event) {
var action = component.get("c.fetchAccount");
action.setParams({
'searchKeyWord': component.get("v.searchKeyword")
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var storeResponse = response.getReturnValue();
// if storeResponse size is 0 ,display no record found message on screen.
if (storeResponse.length == 0) {
component.set("v.Message", true);
} else {
component.set("v.Message", false);
}
// set numberOfRecord attribute value with length of return value from server
component.set("v.numberOfRecord", storeResponse.length);
// set searchResult list with return value from server.
component.set("v.searchResult", storeResponse);
}
});
$A.enqueueAction(action);
},
})
=====================================================================================
searchAccountcontroller.js
({
Search: function(component, event, helper) {
var searchKeyFld = component.find("searchId");
var srcValue = searchKeyFld.get("v.value");
if (srcValue == '' || srcValue == null) {
// display error message if input value is blank or null
searchKeyFld.set("v.errors", [{
message: "Enter Search Keyword."
}]);
} else {
searchKeyFld.set("v.errors", null);
// call helper method
helper.SearchHelper(component, event);
}
},
})
=================================================================================
searchAccount1.cmp
<aura:component controller="searchAccountController">
<!--### declared attributes ###-->
<aura:attribute name="searchResult" type="List" description="use for store and display account list return from server"/>
<aura:attribute name="searchKeyword" type="String" description="use for store user search input"/>
<aura:attribute name="Message" type="boolean" default="false" description="use for display no record found message"/>
<aura:attribute name="numberOfRecord" type="integer" default="0" description="use for display Number of records"/>
<div class="slds-m-around--large">
<form class="slds-form--inline">
<div class="slds-form-element">
<label class="slds-form-element__label" for="search"></label>
<div class="slds-form-element__control">
<ui:inputText aura:id="searchId" class="slds-input" value="{!v.searchKeyword}" required="true" placeholder="Type here..."/>
</div>
</div>
<div class="slds-form-element">
<button type="button" onclick="{!c.Search}" class="slds-button slds-button--brand">Search</button>
</div>
</form>
<span class="slds-badge">{!v.numberOfRecord}</span>
<table class="slds-table slds-table--bordered slds-table--cell-buffer">
<thead>
<tr class="slds-text-title--caps">
<th scope="col">
<div class="slds-truncate" title="Id">Id</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Account Name">Account Name</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Type">Type</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Industry">Industry</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Phone">Phone</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Fax">Fax</div>
</th>
</tr>
</thead>
<tbody>
<aura:if isTrue="{!v.Message}">
<div class="slds-text-color--error"> No Result Found...</div>
</aura:if>
<!--### display all records of searchResult attribute by aura:iteration ###-->
<aura:iteration items="{!v.searchResult}" var="acc">
<tr>
<td>
<div class="slds-truncate">{!acc.Id}</div>
</td>
<td>
<div class="slds-truncate">{!acc.Name}</div>
</td>
<td>
<div class="slds-truncate">{!acc.Type}</div>
</td>
<td>
<div class="slds-truncate">{!acc.Industry}</div>
</td>
<td>
<div class="slds-truncate">{!acc.Phone}</div>
</td>
<td>
<div class="slds-truncate">{!acc.Fax}</div>
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
</aura:component>
=======================================================================================================
searchAccountcontroller.apxc
public with sharing class searchAccountController {
@AuraEnabled
public static List < account > fetchAccount(String searchKeyWord) {
String searchKey = searchKeyWord + '%';
List < Account > returnList = new List < Account > ();
List < Account > lstOfAccount = [select id, Name, Type, Industry, Phone, Fax from account where Name LIKE: searchKey];
for (Account acc: lstOfAccount) {
returnList.add(acc);
}
return returnList;
}
}
Please solve this error
Thanks
Manish
({
SearchHelper: function(component, event) {
var action = component.get("c.fetchAccount");
action.setParams({
'searchKeyWord': component.get("v.searchKeyword")
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var storeResponse = response.getReturnValue();
// if storeResponse size is 0 ,display no record found message on screen.
if (storeResponse.length == 0) {
component.set("v.Message", true);
} else {
component.set("v.Message", false);
}
// set numberOfRecord attribute value with length of return value from server
component.set("v.numberOfRecord", storeResponse.length);
// set searchResult list with return value from server.
component.set("v.searchResult", storeResponse);
}
});
$A.enqueueAction(action);
},
})
=====================================================================================
searchAccountcontroller.js
({
Search: function(component, event, helper) {
var searchKeyFld = component.find("searchId");
var srcValue = searchKeyFld.get("v.value");
if (srcValue == '' || srcValue == null) {
// display error message if input value is blank or null
searchKeyFld.set("v.errors", [{
message: "Enter Search Keyword."
}]);
} else {
searchKeyFld.set("v.errors", null);
// call helper method
helper.SearchHelper(component, event);
}
},
})
=================================================================================
searchAccount1.cmp
<aura:component controller="searchAccountController">
<!--### declared attributes ###-->
<aura:attribute name="searchResult" type="List" description="use for store and display account list return from server"/>
<aura:attribute name="searchKeyword" type="String" description="use for store user search input"/>
<aura:attribute name="Message" type="boolean" default="false" description="use for display no record found message"/>
<aura:attribute name="numberOfRecord" type="integer" default="0" description="use for display Number of records"/>
<div class="slds-m-around--large">
<form class="slds-form--inline">
<div class="slds-form-element">
<label class="slds-form-element__label" for="search"></label>
<div class="slds-form-element__control">
<ui:inputText aura:id="searchId" class="slds-input" value="{!v.searchKeyword}" required="true" placeholder="Type here..."/>
</div>
</div>
<div class="slds-form-element">
<button type="button" onclick="{!c.Search}" class="slds-button slds-button--brand">Search</button>
</div>
</form>
<span class="slds-badge">{!v.numberOfRecord}</span>
<table class="slds-table slds-table--bordered slds-table--cell-buffer">
<thead>
<tr class="slds-text-title--caps">
<th scope="col">
<div class="slds-truncate" title="Id">Id</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Account Name">Account Name</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Type">Type</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Industry">Industry</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Phone">Phone</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Fax">Fax</div>
</th>
</tr>
</thead>
<tbody>
<aura:if isTrue="{!v.Message}">
<div class="slds-text-color--error"> No Result Found...</div>
</aura:if>
<!--### display all records of searchResult attribute by aura:iteration ###-->
<aura:iteration items="{!v.searchResult}" var="acc">
<tr>
<td>
<div class="slds-truncate">{!acc.Id}</div>
</td>
<td>
<div class="slds-truncate">{!acc.Name}</div>
</td>
<td>
<div class="slds-truncate">{!acc.Type}</div>
</td>
<td>
<div class="slds-truncate">{!acc.Industry}</div>
</td>
<td>
<div class="slds-truncate">{!acc.Phone}</div>
</td>
<td>
<div class="slds-truncate">{!acc.Fax}</div>
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
</aura:component>
=======================================================================================================
searchAccountcontroller.apxc
public with sharing class searchAccountController {
@AuraEnabled
public static List < account > fetchAccount(String searchKeyWord) {
String searchKey = searchKeyWord + '%';
List < Account > returnList = new List < Account > ();
List < Account > lstOfAccount = [select id, Name, Type, Industry, Phone, Fax from account where Name LIKE: searchKey];
for (Account acc: lstOfAccount) {
returnList.add(acc);
}
return returnList;
}
}
Please solve this error
Thanks
Manish
The code looks good, I have tested this and it is working. You should test it again!.
application code is here then its not working fine
<aura:application extends="force:slds">
<c:searchAccount1 />
</aura:application>