Skip to content
This repository has been archived by the owner on Oct 5, 2022. It is now read-only.

Commit

Permalink
Search event handler is no longer tied to aura:id
Browse files Browse the repository at this point in the history
  • Loading branch information
pozil committed Jul 29, 2019
1 parent 57e0cbc commit 1681912
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ The parent component that contains the lookup must handle the `onSearch` event:
The event handler should do the following:
```js
lookupSearch : function(component, event, helper) {
// Get the lookup component that fired the search event
const lookupComponent = event.getSource();
// Get the Apex server-side action associated with this search (`search` in our samples)
const serverSearchAction = component.get('c.search');
// Passes the action to the lookup component by calling the `search` aura method
component.find('lookup').search(serverSearchAction);
lookupComponent.search(serverSearchAction);
}
```

Expand All @@ -65,13 +67,15 @@ If you need to pass custom parameters like a record id to the Apex search method

```js
lookupSearch : function(component, event, helper) {
// Get the lookup component that fired the search event
const lookupComponent = event.getSource();
// Get the SampleLookupController.search server side action
const serverSearchAction = component.get('c.search');
// You can pass optional parameters to the search action
// but you can only use setParam and not setParams to do so
serverSearchAction.setParam('recordId', component.get('v.recordId'));
// Passes the action to the Lookup component by calling the search method
component.find('lookup').search(serverSearchAction);
lookupComponent.search(serverSearchAction);
},
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="slds-form slds-form_stacked slds-m-around_xx-large">
<lightning:input type="checkbox" label="Is mutli entry lookup" checked="{!v.isMultiEntry}" onchange="{!c.clearSelection}"/>

<c:Lookup aura:id="lookup" selection="{!v.selection}" onSearch="{!c.lookupSearch}" onSelection="{!c.clearErrorsOnChange}" errors="{!v.errors}" label="Search" placeholder="Search Salesforce" isMultiEntry="{!v.isMultiEntry}"/>
<c:Lookup selection="{!v.selection}" onSearch="{!c.lookupSearch}" onSelection="{!c.clearErrorsOnChange}" errors="{!v.errors}" label="Search" placeholder="Search Salesforce" isMultiEntry="{!v.isMultiEntry}"/>

<lightning:button variant="brand" label="Submit" onclick="{!c.onSubmit}" />
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
({
lookupSearch : function(component, event, helper) {
// Get the lookup component that fired the search event
const lookupComponent = event.getSource();
// Get the SampleLookupController.search server side action
const serverSearchAction = component.get('c.search');
// You can pass optional parameters to the search action
// but you can only use setParam and not setParams to do so
serverSearchAction.setParam('anOptionalParam', 'not used');
// Passes the action to the Lookup component by calling the search method
component.find('lookup').search(serverSearchAction);
// Pass the action to the lookup component by calling the search method
lookupComponent.search(serverSearchAction);
},

onSubmit: function(component, event, helper) {
Expand Down

0 comments on commit 1681912

Please sign in to comment.