amp-form:如何使用verifyErrors在多步表单上切换禁用按钮

时间:2018-07-16 16:54:42

标签: forms amp-html

基于表单验证示例here,如果验证返回错误,如何在多步骤表单的第一步中禁用表单按钮(以下示例中的#btn1)?

使用整个表单([disabled]="!user.valid")的有效状态不起作用,因为第二步上可能有一个输入,由于尚未填写,它也会返回verifyErrors。

<form method="post" action-xhr="/submit" verify-xhr="/verify" custom-validation-reporting="as-you-go" on="valid:AMP.setState({ user:{valid: true} })">
    <fieldset class="step1">
      <input id="username>
      <span visible-when-invalid="valueMissing" validation-for="username">
      <span visible-when-invalid="customError" validation-for="username">
    </fieldset>

    <!-- This button should stay disabled if step1 verifyErrors are returned, but should become enabled when step1 verifyErrors are fixed -->
    <button id="btn1" disabled [disabled]="">Continue</button>

    <fieldset class="step2">
      <input id="password">
      <span visible-when-invalid="valueMissing" validation-for="password">
      <span visible-when-invalid="customError" validation-for="password">
    </fieldset>

    <!-- This button stays disabled until the whole form is valid -->
    <button id="btn2" disabled [disabled]="!user.valid">Submit</button>
</form>

问题是,如何根据单个输入的有效性设置状态?

0 个答案:

没有答案