2

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?

3

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 .

  • So it is pretty much using the traditional jQuery style to get the values by either class or id, is that correct? – Lance Shi Mar 26 at 1:55
  • By Id does not work there but by class .Yes almost jQuery style will be ideal . – Mohith Shrivastava Mar 26 at 3:15
2

In my opinion, this is more of how you want to implement and most importantly how would you want to interact with the Users filling in the form. Sometimes one over other is just what you need.

do I still need to add onchange event on every one of the input field at all?

Use this approach if you really want to alert the user about any error in the field right away instead of waiting for end.

Or can I simply collect the information at the submission time?

Use this approach if you want to defer the validation until the submission.

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.