1

We have a Lightning-Record-Edit-Form using layout-type = full to create and update Account. However, due to business needs, we decided to expose limited fields to the users via the layout in our LWC form using lightning-input-field.

Now the business logic needs us to populate values for fields that are not in the UI using the user inputs in the LWC. Since we don't have these fields exposed to UI in the first place we are not able to use this.template.querySelectorAll('lightning-input-field') to manipulate the values for these fields.

Is there any way to still leverage the Lightning-Record-Edit-Form submit capability to update fields that are not part of LWC lightning-input-field html?

1 Answer 1

0

You can add those calculated fields in the onsubmit event of the record-edit-form. HTML

<lightning-record-edit-form 
     record-id={recordId}
     object-api-name={objectApiName}
     onsubmit={handleSubmit}
     ...
>
     ...
</lightning-record-edit-form>

JS

handleSubmit(event){
   event.preventDefault();       // stop the form from submitting
   const fields = event.detail.fields;
   fields.Name = 'name';
   fields.Field1__c = 'feedback';
   fields.Field2__c = 1234;
   this.template.querySelector('lightning-record-edit-form').submit(fields);
}

See the document for more details

2
  • Thanks, I was under the impression event.detail.fields hold only fields that displayed in the UI as part of the form :)
    – ssoundiran
    Feb 20, 2021 at 7:51
  • 1
    @ssoundiran Yes it only holds the fields on the UI, but you can add any additional fields if required, that is what we have done here. Feb 20, 2021 at 8:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .