为什么不遵守显示电子邮件输入的错误消息?
Why doesn't abide show the error message for the email input?
我使用 foundation 及其 abide 插件构建了一个简单的联系表单。它基本上可以工作,除了一件事:电子邮件输入字段的验证。
- 如果我在没有输入任何数据的情况下提交表单,abide 会正确显示两个验证错误消息。
- 如果我在消息
textarea
中输入 just input 并将电子邮件 input
留空,则 abide 会阻止提交表单,但不会显示错误消息。它只是将电子邮件 input
标记为无效。
- 如果我输入了一个有效的电子邮件地址并将消息
textarea
留空,那么尽管电子邮件地址是正确的,但 abide 会显示两条验证错误消息。
你可以在jsbin上查看:https://output.jsbin.com/cacucunama
最小运行示例(与jsbin相同):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>ZURB Foundation Abide form validation error</title>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<link rel="stylesheet" type="text/css"
href="https://cdn.jsdelivr.net/npm/foundation-sites@6.6.3/dist/css/foundation.min.css">
<script type="text/javascript"
src="https://cdn.jsdelivr.net/npm/foundation-sites@6.6.3/dist/js/foundation.min.js"></script>
</head>
<body>
<form action="#" method="get" enctype="multipart/form-data" data-abide novalidate id="footer-contact-form">
<div class="input-group">
<span class="input-group-label">N</span>
<input name="user[name]" value="" type="text" id="footer-contact-form--name" class="input-group-field"
placeholder="Name">
</div>
<div class="input-group">
<span class="input-group-label">@</span>
<input name="user[email]" value="" type="email" id="footer-contact-form--email" class="input-group-field"
placeholder="Email address*" required pattern="email">
</div>
<label class="form-error" data-form-error-for="footer-contact-form--email">Valid email required.</label>
<textarea name="user[message]" id="footer-contact-form--message" placeholder="Message*" rows="3"
required=""></textarea>
<label class="form-error" data-form-error-for="footer-contact-form--message">A message is required.</label>
<button value="" type="submit" class="button expanded">Send</button>
</form>
</body>
</html>
正如在 https://foundation.discourse.group/t/abide-doesnt-show-the-correct-validation-error-message/2276/10 中已经回答的那样,您忘记在带有电子邮件输入和消息文本区域的部分中包装标签 + 输入参数。
https://codepen.io/DanielRuf/pen/dyYpjYZ
它适用于以下代码:
<form action="#" method="get" enctype="multipart/form-data" data-abide novalidate id="footer-contact-form">
<div class="input-group">
<span class="input-group-label">N</span>
<input name="user[name]" value="" type="text" id="footer-contact-form--name" class="input-group-field"
placeholder="Name">
</div>
<div>
<div class="input-group">
<span class="input-group-label">@</span>
<input name="user[email]" value="" type="email" id="footer-contact-form--email" class="input-group-field"
placeholder="Email address*" required pattern="email">
</div>
<label class="form-error" data-form-error-for="footer-contact-form--email">Valid email required.</label>
</div>
<div>
<textarea name="user[message]" id="footer-contact-form--message" placeholder="Message*" rows="3"
required=""></textarea>
<label class="form-error" data-form-error-for="footer-contact-form--message">A message is required.</label>
</div>
<button value="" type="submit" class="button expanded">Send</button>
</form>
我使用 foundation 及其 abide 插件构建了一个简单的联系表单。它基本上可以工作,除了一件事:电子邮件输入字段的验证。
- 如果我在没有输入任何数据的情况下提交表单,abide 会正确显示两个验证错误消息。
- 如果我在消息
textarea
中输入 just input 并将电子邮件input
留空,则 abide 会阻止提交表单,但不会显示错误消息。它只是将电子邮件input
标记为无效。 - 如果我输入了一个有效的电子邮件地址并将消息
textarea
留空,那么尽管电子邮件地址是正确的,但 abide 会显示两条验证错误消息。
你可以在jsbin上查看:https://output.jsbin.com/cacucunama
最小运行示例(与jsbin相同):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>ZURB Foundation Abide form validation error</title>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<link rel="stylesheet" type="text/css"
href="https://cdn.jsdelivr.net/npm/foundation-sites@6.6.3/dist/css/foundation.min.css">
<script type="text/javascript"
src="https://cdn.jsdelivr.net/npm/foundation-sites@6.6.3/dist/js/foundation.min.js"></script>
</head>
<body>
<form action="#" method="get" enctype="multipart/form-data" data-abide novalidate id="footer-contact-form">
<div class="input-group">
<span class="input-group-label">N</span>
<input name="user[name]" value="" type="text" id="footer-contact-form--name" class="input-group-field"
placeholder="Name">
</div>
<div class="input-group">
<span class="input-group-label">@</span>
<input name="user[email]" value="" type="email" id="footer-contact-form--email" class="input-group-field"
placeholder="Email address*" required pattern="email">
</div>
<label class="form-error" data-form-error-for="footer-contact-form--email">Valid email required.</label>
<textarea name="user[message]" id="footer-contact-form--message" placeholder="Message*" rows="3"
required=""></textarea>
<label class="form-error" data-form-error-for="footer-contact-form--message">A message is required.</label>
<button value="" type="submit" class="button expanded">Send</button>
</form>
</body>
</html>
正如在 https://foundation.discourse.group/t/abide-doesnt-show-the-correct-validation-error-message/2276/10 中已经回答的那样,您忘记在带有电子邮件输入和消息文本区域的部分中包装标签 + 输入参数。
https://codepen.io/DanielRuf/pen/dyYpjYZ
它适用于以下代码:
<form action="#" method="get" enctype="multipart/form-data" data-abide novalidate id="footer-contact-form">
<div class="input-group">
<span class="input-group-label">N</span>
<input name="user[name]" value="" type="text" id="footer-contact-form--name" class="input-group-field"
placeholder="Name">
</div>
<div>
<div class="input-group">
<span class="input-group-label">@</span>
<input name="user[email]" value="" type="email" id="footer-contact-form--email" class="input-group-field"
placeholder="Email address*" required pattern="email">
</div>
<label class="form-error" data-form-error-for="footer-contact-form--email">Valid email required.</label>
</div>
<div>
<textarea name="user[message]" id="footer-contact-form--message" placeholder="Message*" rows="3"
required=""></textarea>
<label class="form-error" data-form-error-for="footer-contact-form--message">A message is required.</label>
</div>
<button value="" type="submit" class="button expanded">Send</button>
</form>