I want to check on my custom onchange event which fieldName is being changed but when I try to retrieve info via event.detail.fieldName or event.detail.field-name it gives me undefined.


    var eventName = event.detail.fieldname;


<lightning-input-field field-name="AccountId" onchange={handleInputChange}></lightning-input-field>

How can I get field-name value via event in handleInputChange method?


event.detail will give you the data sent in event and event.target (or event.currentTarget) will give you the details about the elements.

Currently you are looking for attributes on source element so you should be using event.target. Below will give you fieldName:

handleInputChange(event) {
    console.log('fieldName => ', event.target.fieldName);

Also note

NOTE Property names in JavaScript are in camel case while HTML attribute names are in kebab case (dash-separated) to match HTML standards. In todoApp.html, the item-name attribute in markup maps to the itemName JavaScript property of c-todo-item.

Same applies even for attributes - called from same component JS.

  • Thanks! That's exactly what I needed!
    – molinet
    Sep 23 '19 at 15:43

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.