简体   繁体   English

如果Google amp中的表单为空,则显示错误消息

[英]Show error message if form empty in google amp

Is there any way to show an error message if a form is empty in AMP(ie none of the fields have any value?). 如果AMP中的表单为空(即没有任何字段具有任何值?),有没有办法显示错误消息。 I tried the following, but it does not seem to work(Please not the div.error node). 我尝试了以下操作,但它似乎不起作用(请不要div.error节点)。

<form method="POST" id="my-form" class="p2" action-xhr="/components/amp-form/submit-form" target="_top" custom-validation-reporting="show-first-on-submit">
  <p>My Form</p>
  <div class="error" visible-when-invalid="valueMissing" validation-for="my-form">
    Form is empty could not submit.
  </div>
  <div>
    <input required id="username" type="text" placeholder="username" name="username">
    <input required id="password" type="password" placeholder="password" name="password">
  </div>
  <input type="submit" value="OK">
</form>

Try with validation state invalid like on="invalid:error.show" 尝试使用无效的验证状态,例如on="invalid:error.show"

invalid : The form's validation state to "invalid" (in accordance with its reporting strategy ). invalid:表单的验证状态为“无效”(根据其报告策略 )。

<form method="POST" id="my-form" class="p2" action-xhr="/components/amp-form/submit-form" target="_top" on="invalid:error.show" custom-validation-reporting="show-first-on-submit">
  <p>My Form</p>
  <div class="error" id="error" hidden>
    Form is empty could not submit.
  </div>
  <div>
    <input required id="username" type="text" placeholder="username" name="username">
    <input required id="password" type="password" placeholder="password" name="password">
  </div>
  <input type="submit" value="OK">
</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM