[SalesForce] Lightning Web Component – do I need to track changes for every single input field in a form

Since lwc is one-way data binding so if I need to get the current value of the input field I turned out to use event.target.value in the onchange event.

However, if we need to have a form of input fields and only need to collect all of the data at the form submission time, do I still need to add onchange event on every one of the input field at all? Or can I simply collect the information at the submission time?

Best Answer

I would simply collect all the information on form submission using query selector.

this.template.querySelector('classname'); //use query selector

Note that @track should not be used extensively . It makes less sense to use this decorator if we are not rendering something on the UI .

If there is no client side validations involved on page, there is no need to use change handler on every input .

Related Topic