I'm working on a new form in React, where I need to validate inputs and, in case of incorrect input, display alerts individually under each bad input.
What is the better solution?
- Create a div in advance under each input and hide and show it with the help of classes.
<label htmlFor="first-name"></label>
<input type="text" name="first-name" id="first-name" />
<div className="invalid-input disable/enable">Please fill in your name.</div>
- Create an auxiliary function that performs validation and then adds this warning div under each input.
const div = document.createElement("div")
div.innerHTML = "Please fill in your name.";
const input = document.getElementById("first-name");
insertAfter(div, input);
What is conventionally correct?