Solution 1 :

Can you try with input type reset, or reset function on clear button

Problem :

I have added the following function to simply remove a field when clear button is clicked. The err I am getting is:

Uncaught TypeError: Cannot read property ‘classList’ of null

To fix that I tried to add the class positionInput inside the div for the input field;that didn’t fix it of course.

_clear() {
  var newPosition = document.getElementById("position");
  newPosition.classList.remove("positionInput");
}

Here is the object that injects the new form input field:

_addPosition(e) {

   let newPosition = document.createElement('input');               
   newPosition.classList = 'positionInput';                
   positionGroup.insertAdjacentElement('beforeend', newPosition);
}

And here is the markup for input filed and clear button

 <div style="display: flex; margin: 0.5em 0 1em 0;">
    <input style="margin-right: 10px;" type="button" value="SAVE" on-click="_post" />
    <input type="button" value="CLEAR" on-click="_clear" />
</div>

Comments

Comment posted by Fighithebird

I should add the html for input field as well:

By