need details on event.target.getSelection()
padmaneela123 opened this issue · 6 comments
in handleLookupSelectionChange(event) all I am getting is selected ID but not complete object attribute/field values. I have situation on parent we have two lookups I want check based sObjectType value I want to call different APEX method. Please advise.
HI @padmaneela123, I'm not sure to fully understand your use case.
If I get this right, you need to pass extra data to the search handler. This is documented here: Passing custom data to JavaScript and Apex
Ok, now I understand a bit better.
If you're working with different objects in separate lookups, I would advise you to create different handleLookupSelectionChange
methods and dedicated Apex search endpoints so that there's no confusion on the object types.
<c-lookup
onsearch={handleSearchUser}
onselectionchange={handleUserSelectionChange}
label="Search for a user">
</c-lookup>
<c-lookup
onsearch={handleSearchBadge}
onselectionchange={handleBadgeSelectionChange}
label="Search for a badge">
</c-lookup>
If you really don't want to do this then, proceed with my initial suggestion and add a custom data attribute (data-type
in the example below) that gives you the object type.
<c-lookup
onsearch={handleSearch}
onselectionchange={handleSelectionChange}
label="Search for a user"
data-type="User">
</c-lookup>
<c-lookup
onsearch={handleSearch}
onselectionchange={handleSelectionChange}
label="Search for a badge"
data-type="Badge">
</c-lookup>
Then, figure out the object type in JS:
handleSelectionChange(event) {
const lookupElement = event.target;
alert(lookupElement.dataset.type); // User or Badge
}
Thanks for the details.