0

Project and Unit in a Master-detail relationship Project-Master object Unit - detail object Price - another custom object Price contains two custom lookup fields Project, Unit I have created a custom input form for 'Price' object using lightning web components. I had defined the fields Project, Unit as:

 <lightning-input-field field-name="Unit__c" value ={unitVal}>
 </lightning-input-field>
  </lightning-record-edit-form>
  </template>

But when I did so, all projects got listed out in 'Project' field, but 'Unit' field is empty And also the filter is not working, I need to filter the values of 'Unit' that comes under the selected project.

JS

projectChange(event) {
   
  
   this.projSelected = event.detail.value[0];

   getUnit({ projId:this.projSelected })

   .then(result => {

    this.unitVal = result;
      })

   .catch(error => {
    this.unitVal = undefined;


   });

Apex class

@AuraEnabled(cacheable = true) public static List<Unit__c> getUnit(Id projId) {

    return [SELECT Id,  Name FROM Unit__c where Project__c = :projId ];
}


Is there any mistake in my code?
0
<lightning-input-field field-name="Unit__c" value ={unitVal}>
</lightning-input-field>

In your code, you have used the unit records list for the "value" attribute, but lightning-input-field will not admit that. You can only provide the Id of any unit record to the "value" attribute.

Besides, you can show the unit records in a custom picklist and get the Id of the selected unit record and provide it to the "Unit__c" field of the project at the time of submit of the project record.

4
  • Hi Avi, is there any other way to do this? – Athira Venugopal Sep 29 '20 at 6:44
  • Either you can go for a custom picklist to show Unit records or go with the custom LookUp component. – Avi Rai Sep 29 '20 at 7:48
  • Is it possible using a lightning:combobox? – Athira Venugopal Sep 29 '20 at 10:13
  • Yes, that is good. – Avi Rai Sep 29 '20 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.