1

I have this below lightning-record-edit-form. I want to get the value from Name lightning-input-field so that i can do some manipulation at javascript end.

Currenlty i am getting null on load of the form.

How to get the value.

HTML

<lightning-record-edit-form record-id={recordId} object-api-name="Test__c" onload={handleOnLoad}>
<lightning-input-field variant="label-stacked" class="name" field-name="Name"></lightning-input-field>
</lightning-record-edit-form>

JS -

  handleOnLoad() {
        let name= this.template.querySelector('.name');
        alert(name);
    }

1 Answer 1

7
handleOnLoad() {
    let name = this.template.querySelector('.name').value;
    alert(name);
}

This will work.

BUT above approach is not good. You can get all the values based on recordId as below

handleOnLoad(event) {
    var record = event.detail.records;
    var fields = record[this.recordId].fields; // record['0010K000026Y******'].fields;
    const accName = fields.Name.value;      
    alert(accName);
    //const myfieldVal = fields.myfield__c.value;
    //alert(myfieldVal);
}
5
  • Hi @salesforcesas .. it worked for inputfield perfectly.. but for lightning-output-field it is giving "undefined" error. is there any workaround.. Commented Jul 25, 2019 at 9:36
  • pls mark as accepted if it solved Commented Jul 25, 2019 at 10:42
  • 1
    Apologies.. for tht Commented Aug 22, 2019 at 11:30
  • Hi @salesforce-sas, I have tried the same as follows var recordsMap = event.detail.records; var record = recordsMap[this.recordId]; but at line 2, nothing is found with that ID and returning undefined. Help me where I'm going wrong here.
    – Dinesh KR
    Commented Aug 20, 2020 at 19:56
  • it seems there is a issue console.log("OnLoadData-", JSON.stringify(event.detail.records)); is returning undefined. Commented Sep 20, 2021 at 4:05

You must log in to answer this question.

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