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.
js:
handleInputChange(event){
var eventName = event.detail.fieldname;
console.log(eventName);
}
cmp:
<lightning-input-field field-name="AccountId" onchange={handleInputChange}></lightning-input-field>
How can I get field-name
value via event in handleInputChange method?
Best Answer
event.detail
will give you the data sent in event andevent.target
(orevent.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:Also note
Same applies even for attributes - called from same component JS.