无法在表单提交成功事件AMP上设置State



当我在submit success事件中提交一个表单时,我试图提交另一个表单,但这会导致一个信任级别错误,指出submit suc成功没有设置状态的相同信任级别。我检查了amp表单提交事件和setState事件具有与HIGH相同的信任级别,但没有找到提交成功事件的信任级别

"submit-success" event with "low" trust is not allowed to invoke "amp.setState".

伪示例

<form id="f1" method="POST" xhr-action="dummyapi" on="submit-success:AMP.setState({dummy:true})">
<!--fields-->
</form>
<form id="f2" method="POST" xhr-action="dummyapi" on="submit-success:f1.submit">
<!--fields-->
</form>

提交表单f1时的setState不起的作用

Buddy,你的代码在哪里?为什么不能插入一个简单有效的AMP模板?你可能希望有人为你做每件事,但这种情况并不总是发生。


我试着做你写的,一切都对我有效,看:

<!--
This is the minimum valid AMP HTML document. Type away
here and the AMP Validator will re-check your document on the fly.
-->
<!DOCTYPE html>
<html ⚡>
<head>
<meta charset="utf-8" />
<link rel="canonical" href="self.html" />
<meta name="viewport" content="width=device-width,minimum-scale=1" />
<style amp-boilerplate>
body {
-webkit-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
-moz-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
-ms-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
animation: -amp-start 8s steps(1, end) 0s 1 normal both;
}

@-webkit-keyframes -amp-start {
from {
visibility: hidden;
}
to {
visibility: visible;
}
}

@-moz-keyframes -amp-start {
from {
visibility: hidden;
}
to {
visibility: visible;
}
}

@-ms-keyframes -amp-start {
from {
visibility: hidden;
}
to {
visibility: visible;
}
}

@-o-keyframes -amp-start {
from {
visibility: hidden;
}
to {
visibility: visible;
}
}

@keyframes -amp-start {
from {
visibility: hidden;
}
to {
visibility: visible;
}
}
</style>
<noscript>
<style amp-boilerplate>
body {
-webkit-animation: none;
-moz-animation: none;
-ms-animation: none;
animation: none;
}
</style>
</noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
</head>
<body>
<h2>First form</h2>
<form id="secondForm" method="post" target="_top" action-xhr="https://amp.dev/documentation/examples/api/echo">
<input type="hidden" value="hiddenValue">
<div submit-success>Second form send successful!</div>
<div submit-error>Second form send failed!</div>
</form>
<hr>
<h2>Second form</h2>
<form id="firstForm" method="post" target="_top" action-xhr="https://amp.dev/documentation/examples/api/verify-form-input-text-xhr" on="submit-success:secondForm.submit">
<button type="submit">Submit</button>
<div submit-success>First form send successful!</div>
<div submit-error>First form send failed!</div>
</form>
</body>
</html>

代码笔:https://codepen.io/alexandr-kazakov/pen/wvGJvzJ?editors=1000

相关内容

  • 没有找到相关文章

最新更新