Safari 的 AMP 表单验证

AMP form validation for Safari

AMP 表单只允许我使用 HTML5 表单验证来验证用户输入。它在桌面 Chrome 浏览器中运行良好。但是 Safari 直到现在才支持 HTML5 表单验证。我找到了解决方案,需要外部 Javascript 才能在 Safari 浏览器上实现表单验证。但就我而言,AMP 不允许我这样做。

Is there any hacks or trick to bypass HTML5 validation inputs for Safari?

在此HTML5 documentation中提到:

Even though Safari supports the constraint validation API, as of this writing (version 6), Safari will not prevent submission of a form with constraint validation issues.

The easiest way around this is to use the same approach as the workaround described above, give all forms the novalidate attribute and manually prevent form submissions using preventDefault.

有了这个,您可能想查看这个 thread wherein it gives guidelines regarding AMP Forms Support and also issues to track such as Forms should respect the novalidate attribute. View given codes here 看看它会对您有所帮助。

尝试将您的 AMP 文档与 AMP by Example amp-form demo 进行比较。 amp-form 扩展为不支持本机验证的浏览器实现了表单验证 API polyfill。如果您在没有本机支持的 ​​Safari 版本中使用 amp-form,polyfill 行为应该自动 运行。

polyfill 验证应如下所示: