You need to sign in to do that
Don't have an account?
Pavushetti Abhilash 3
Show custom object field values in LWC combobox dropdown
Hi everyone.
I have a custom object Address__c. In address there are few fields called Strret, Colony, City, State, Country. In LWC combobox drop down, these custom object fields should display. Please let me know the required code part. For example just like in Amazon while selecting delivery we will get picklist values with addresses linked to account. If we have 4 addresses amazon will ask in dropdown the ask to select one address.
I have a custom object Address__c. In address there are few fields called Strret, Colony, City, State, Country. In LWC combobox drop down, these custom object fields should display. Please let me know the required code part. For example just like in Amazon while selecting delivery we will get picklist values with addresses linked to account. If we have 4 addresses amazon will ask in dropdown the ask to select one address.
Try Below Code Please Mark It As best Answer If It Helps
Thank You!
<lightning-combobox
name="Collection Address"
value={value}
options={Options}
onchange={handleChange}></lightning-combobox>
----------------------------------------JS--------------------------------------
@track Options =[];
setofAddress= [];
@wire(getCollectionAddress, {userid: USER_ID})
wiredclass({data, error}){
if(data){
console.log(data);
const addressVal = data;
let setOptions = Object.values(addressVal);
for(let i = 0; i<setOptions.length; i++){
//console.log(setOptions[i].r4c_Street1__c+','+setOptions[i].r4c_Street2__c+','+setOptions[i].r4c_City__c)
this.setofAddress.push(setOptions[i].r4c_Street1__c+','+setOptions[i].r4c_Street2__c+','+setOptions[i].r4c_State_Province__c+','+setOptions[i].r4c_City__c+','+setOptions[i].Country__c+','+setOptions[i].r4c_Zip_Postal_Code__c);
}
console.log(this.setofAddress);
this.Options = this.genSiteAddress(this.setofAddress);
}
if(error){
console.log(error);
}
genSiteAddress(data){
//console.log(data)
return data.map(item=>({label:item, value:item}))
}
handleChange(event) {
alert(event.detail.value);
}
------------------------------APEX CLASS-----------
@AuraEnabled(cacheable=true)
public static List<r4c_Collection_Address__c> getCollectionAddress(String userid){
Id LoggedInUserID = userid;
User getcustomerUserId = [Select ID,AccountId From User WHERE ID=: LoggedInUserID];
ID customerAccount = getcustomerUserId.AccountId;
List<r4c_Collection_Address__c> collectionAddress = new List<r4c_Collection_Address__c>();
collectionAddress = [SELECT ID,r4c_Street1__c,r4c_Street2__c,r4c_City__c,r4c_Zip_Postal_Code__c,
r4c_State_Province__c,Country__c FROM r4c_Collection_Address__c WHERE Account_Name__r.Id =: customerAccount];
return collectionAddress;
}