我有一个多页的表单,在此表单中,我只想在所有字段填写完毕后才允许“下一个”按钮起作用。我遵循了以下链接;
<div class="stepper vertical">
<button class="step-title step-active"
[class]="currentStep > 0 ? 'step-title' : 'step-title step-active'"
on="tap:AMP.pushState({ currentStep: 0 })">
<i class="step-incomplete"
[class]="animalSelected ? 'step-complete' : 'step-incomplete'"
data-step-nr="1"></i>
Animal
</button>
<section [hidden]="currentStep > 0">
<div class="content">
<p>What's your favorite animal?</p>
<amp-selector on="select:AMP.setState({animalSelected: true})"
class="poll"
name="animal-poll">
<div option="cat">Cat</div>
<div option="dog">Dog</div>
<div option="horse">Horse</div>
</amp-selector>
<button disabled
[disabled]="!animalSelected"
on="tap:AMP.pushState({ currentStep: currentStep + 1 })">
continue
</button>
</div>
</section>
<button class="step-title"
[class]="currentStep != 1 ? 'step-title' : 'step-title step-active'"
disabled
[disabled]="!animalSelected"
on="tap:AMP.pushState({ currentStep: 1 })">
<i class="step-incomplete"
[class]="colorSelected ? 'step-complete' : 'step-incomplete'"
data-step-nr="2"></i>
Color
</button>
<section hidden
[hidden]="currentStep != 1">
<div class="content">
<p>What's your favorite color?</p>
<amp-selector on="select:AMP.setState({colorSelected: true})"
class="poll"
name="color-poll">
<div option="blue">Blue</div>
<div option="green">Green</div>
<div option="yellow">Yellow</div>
</amp-selector>
<button disabled
[disabled]="!colorSelected"
on="tap:AMP.pushState({ currentStep: currentStep + 1 })">
continue
</button>
</div>
</section>
<button class="step-title"
[class]="currentStep != 2 ? 'step-title' : 'step-title step-active'"
disabled
[disabled]="!colorSelected"
on="tap:AMP.pushState({ currentStep: 2 })">
<i class="step-incomplete"
[class]="fruitSelected ? 'step-complete' : 'step-incomplete'"
data-step-nr="3"></i>
Fruit
</button>
<section hidden
[hidden]="currentStep != 2">
<div class="content">
<p>What's your favorite fruit?</p>
<amp-selector on="select:AMP.setState({fruitSelected: true})"
class="poll"
name="fruit-poll">
<div option="apple">Apple</div>
<div option="banana">Banana</div>
<div option="cheery">Cheery</div>
</amp-selector>
<button disabled
[disabled]="!fruitSelected"
on="tap:AMP.pushState({ currentStep: currentStep + 1 })">
continue
</button>
</div>
</section>
</div>
哪个显示了如何通过单个单选按钮可以实现此目的,但是,如何将其扩展到适用于同一部分中的多个输入呢?
除了简单地禁用按钮之外,是否还可以单击按钮时提供某种反馈(即触发所需输入的错误弹出窗口)?
答案 0 :(得分:0)
您可以在绑定中使用表达式:
请参阅:https://www.ampproject.org/docs/reference/components/amp-bind#expressions
类似的东西
[disabled] = "!select1 || !select2"
其中“ select1”和“ select2”来自各自的输入。