I'm noticing some strange behavior with forms in react. I'm using a button with a handleSubmit function for the onClick attribute, but it is not technically a submit button for the form. Nevertheless, parts of the handleSubmit function are not working even when they are exactly the same lines of code from other functions. I believe the form is submitting on click of the button, but I have not designated this button as a submit button for the form. It's just a button.
<button
class="button is-dark"
onClick={(e) => handleSubmit(e, listItem.album.albumid, document.getElementById('scoreNum'+ listItem.index).value, listItem.index)}
disabled={setDisabledInputs()}
>
Submit
</button>
This function works fine:
const onClear = (item) => {
document.getElementById('scoreNum' + item).removeAttribute("value")
document.getElementById('scoreRange' + item).value = document.getElementById('scoreRange' + item).defaultValue
}
When I use one of the same lines of code in the handleSubmit function, it doesn't work, and the page refreshes as if the form has been submitted unless I use event.preventDefault():
const handleSubmit = (event, albumid, rating, item) => {
document.getElementById('scoreNum' + item).removeAttribute("value") //why doesn't this work
}
I would expect the handleSubmit function to just do the code I wrote and nothing else.