1
    [inpTitle, inpBody].forEach(inputField => {
        inputField.addEventListener("blur", () => {
            const updatedTitle = inpTitle.value.trim();
            const updatedBody = inpBody.value.trim();

            this.onNoteEdit(updatedTitle, updatedBody);
        });
    });

this error is being shown in the console too Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')

  • 1
    How ever you've defined `inpTitle` and `inpBody` variables, at least one of them is `null`. See https://stackoverflow.com/q/14028959/1169519 – Teemu Mar 17 '22 at 13:03
  • Please provide enough code so others can better understand or reproduce the problem. – Community Mar 17 '22 at 13:04

1 Answers1

0

You can add an if statement to check if the inputField exists, but there should be other ways to make sure that you don't have an empty input.

[inpTitle, inpBody].forEach(inputField => {
  if(inputField){
    inputField.addEventListener("blur", () => {
        const updatedTitle = inpTitle.value.trim();
        const updatedBody = inpBody.value.trim();

        this.onNoteEdit(updatedTitle, updatedBody);
    });
   }
});
Elvis
  • 26
  • 3