0

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
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);
}
  • Hi @salesforcesas .. it worked for inputfield perfectly.. but for lightning-output-field it is giving "undefined" error. is there any workaround.. – learningmode Jul 25 at 9:36
  • pls mark as accepted if it solved – salesforce-sas Jul 25 at 10:42
  • I think you should start accepting answers if solved when people take time out to help you. – salesforce-sas Aug 22 at 11:28
  • 1
    Apologies.. for tht – learningmode Aug 22 at 11:30

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.