0

As I studied this documentation
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_data_change.htm
I understand that I need to create change handler
<aura:handler name="change" value="{!v.numItems}" action="{!c.itemsChange}"/>
attribute for each of the input value I need to keep track of.
Now My page can have 500 inputs, so I do not feel it wise to 500 create change handler, since it may make the page heavy

Instead I prefer using simple HTMl5 event listener. i.e. document.getElementById("abc").addEventListener("change",handler);
I know using onchange attribute on the input or component might not work since that cancelled by component

My question is thus is there any harm in using html5 event listener instead of lightning change handler attribute?
Or in other words what is the necessity of creating change handler attribute, when same can be done using normal html event listener?

1

Even if you use HTML5 events, the native event gets wrapped by Locker Service, so you won't necessarily have access to all of the event attributes that you might expect if you weren't working with Lightning.

For your scenario, it would make more sense to wrap your input element inside a custom component. Then, in the custom component, you can use an <aura:handler> and fire a custom lightning event with whatever details you need. Finally, your top-level component would have a single listener for that event type.

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.