Assume that you are working on Account
object & its Notes__c
field using lightning-record-edit-form
. In the component JS file, you would import the field using the following code:
import NOTES_FIELD from '@salesforce/schema/Account.Notes__c';
and declare a field using the following code:
notes = NOTES_FIELD;
In the component HTML file, the input field would be declared, along with a button, as given in the code snippet below:
<lightning-input-field field-name={notes}></lightning-input-field>
<lightning-button class="slds-m-top_small" label="Unlock" onclick={handleUnlock}></lightning-button>
In the handleUnlock
JS Method, you can reset the required fields as shown below:
handleUnlock(event) {
// Write code to unhide the 'Save' button here.
const inputFields = this.template.querySelectorAll('lightning-input-field');
if (inputFields) {
inputFields.forEach(field => {
if(field.fieldName === this.notes.fieldApiName) {
field.reset();
}
// Write additional IF conditions or any other conditional logic to reset the field.
});
}
}
If you need to set a specific value to the field, then you should do the following. In the component JS file, declare a field to hold the input field value as notesValue;
and in the component HTML file, declare the input field HTML as follows:
<lightning-input-field field-name={notes} value={notesValue}></lightning-input-field>
In the handleUnlock
JS Method, you can update the required field values as shown below:
handleUnlock(event) {
// Write code to unhide the 'Save' button here.
this.notesValue = '<Place required value here>';
}