[英]Form won't submit with custom validation error message
I wanted to create a custom validation error message.我想创建一个自定义验证错误消息。 When I try to submit my form, without filling the input box I get the custom error message.
当我尝试提交表单时,未填写输入框,我收到自定义错误消息。 However, even when I fill up the input box the form does not submit I get my custom validtion error message.
但是,即使我填写了输入框,表单也没有提交,我也会收到我的自定义验证错误消息。
<input name="trailerNumber" class="form-control" type="text" aria-describedby="enter Part Number" placeholder="Trailer Number" oninvalid="this.setCustomValidity('Trailer Number must be filled to initiate order')"
onvalid="this.setCustomValidity('')">
Is there a way to set custom validatoin on required field?有没有办法在必填字段上设置自定义验证?
Instead of using the onvalid
event listener, try the oninput
or onchange
events to reset the custom validity.尝试使用
oninput
或onchange
事件来重置自定义有效性,而不是使用onvalid
事件侦听器。
According to MDN, there is no onvalid
event handler.根据 MDN,没有
onvalid
事件处理程序。
<form action="" onsubmit="event.preventDefault(); alert('Submitted')" method="GET"> <input name="trailerNumber" required="required" minlength="5" placeholder="Trailer Number" oninvalid="this.setCustomValidity('Trailer Number must be filled to initiate order')" oninput="this.setCustomValidity('')" > <input type="submit" value="Submit"> </form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.