Skip to content

Instantly share code, notes, and snippets.

@paustint
Created April 7, 2018 02:00
Show Gist options
  • Save paustint/7535bd0adf006d95808e4a6e4f3e8bac to your computer and use it in GitHub Desktop.
Save paustint/7535bd0adf006d95808e4a6e4f3e8bac to your computer and use it in GitHub Desktop.
({
handleComboBoxChangedEvent: function(component, event, helper) {
var params = event.getParams();
if(params.type === 'searchTermChanged') {
component.set('v.comboLoading', true);
helper.searchAccounts(component, params.searchTerm)
.then(function(data) {
component.set('v.searchedAccounts', data.map(function(rec) {
return {
record: rec,
name: rec.Id,
label: rec.ZVP_Franchise_Display_Name__c,
}
}));
component.set('v.comboLoading', false);
})
.catch(function(err) {
// utils.error('Error searching accounts', err);
// ERROR - handle gracefully
});
} else if (params.type === 'selectedItemChanged') {
component.set('v.comboLoading', false);
// TODO: allow array in future (if we want multi-select)
var selectedAccountId = params.selectedItem.name;
var searchedAccounts = component.get('v.searchedAccounts');
// find account - NOTE: you will need to add a polyfill for IE or modify to use Array.indexOf();
var selectedAccount = searchedAccounts.find(function(account) { account.Id === selectedAccountId });
component.set('v.selectedAccount', selectedAccount);
}
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment