如何提交表单只有当某些条件与其他表单匹配?
我正在使用AMP。我要求用户的手机号码,然后hit api(let's X)。如果响应成功,则向用户显示结果,如果响应是error then I asked otp。进入otp后点击验证我hit api(let's Y)。 API的回应如下。如何提交表单只有当某些条件与其他表单匹配?
Response code=200 code=1 or 2 or 3 
Response code=400 
Message:"some error" 
在API Y和if code=1 then only I want to hit api X的success响应。我不知道该怎么做。以下是我所做的。
<form method="post"      id="form1" 
     action-xhr="url of X api" 
     on="submit-error:otpScreen.show"> 
. 
. 
. 
</form> 
<form method="get" 
     action-xhr="url of Y api" 
     on="submit-success:event.response.code==1?form1.submit:otpScreen.hide" //here i getting syntax error 
> 
<div id='otpScreen'>.......</div> 
</form> 
甚至有可能从第一种形式提交第二种形式的一些条件?
回答:
使用amp-bind禁用第二个窗体的提交按钮,直到提交第一个窗体。例如:
<form id=form1 on="submit-success:AMP.setState({form1Success: true})">...</form> <form id=form2> 
    ... 
    <input type=submit disabled [disabled]="!form1Success"> 
</form> 
...或者你可以使用hidden属性隐藏第二种形式:
<form id=form1 on="submit-success:AMP.setState({form1Success: true})">...</form> <form id=form2 hidden [hidden]="!form1Success"> 
    ... 
</form> 
以上是 如何提交表单只有当某些条件与其他表单匹配? 的全部内容, 来源链接: utcz.com/qa/265507.html

