I am trying to prevent form submission if the password !== &&.
I have an expression that works already if the passwords don’t match or are not up to standard:
const password = form.watch("password");
const confirmPassword = form.watch("confirmPassword");
const handleConfirmPasswordBlur = () => {
setConfirmPasswordTouched(true);
};
Which works with this:
<InputWithLabel
id="password"
label="Password:"
placeholder={authFormConstants.placeholderPassword}
type="password"
register={form.register("password")}
horizontal
/>
{password !== "" && (
<div className="col-start-2 col-span-3">
<ValidationList rules={passwordRules} value={password} />
</div>
)}
However, I want to have those same errors show up if the password does not equal an empty string as well as if the form is submitted without any password inputs.
In plain JS I would usually handle it with something like this:
document.getElementById("myForm").addEventListener("submit", function(event) {
var password = document.getElementById("password").value;
// Prevent form submission if password is not empty
if (password !== "") {
event.preventDefault();
alert("Password must be empty to submit the form.");
}
});
However, this does not work in my case.
