[英]I want to validate that input-label has a value if other input-control has set certain value
As I said in the title, I have a dropdown list with 2 values - yes and no, and another input label where you can write freely. 就像我在标题中所说的,我有一个带有2个值的下拉列表-是和否,以及另一个可以自由编写的输入标签。 I want to validate that if the user chose "yes", also the input label is filled and vice versa - if "no" was chosen I want to make sure that the input label is empty.
我想验证一下,如果用户选择“是”,则输入标签也会被填充,反之亦然-如果选择了“否”,我要确保输入标签为空。
For making sure, that if "no" was chosen label will be empty, I tried simply blocking the label when "no" is chosen but it is not enough as a user can choose "yes" then write something and switch back to "no" 为了确保,如果选择了“否”,标签将为空,那么我尝试在选择“否”时仅阻止标签,但这还不够,因为用户可以选择“是”,然后写点内容并切换回“否” ”
<div class="select-wrapper" [ngClass]="{'select-wrapper-blocked': isNotAdmin()}">
<select class="input-control" [(ngModel)]="booleanVariable">
<option value="false">No</option>
<option value="true">Yes</option>
</select>
</div>
</div>
<div class="col form-input" [ngClass]="{'form-input-blocked': isNotAdmin()}">
<p class="input-label">
Some text
</p>
<input class="input-control" [(ngModel)]="stringVariable" />
</div>
You can wrap input label in a <span>
and display it only when user selects "yes" ie booleanVariable
is true
您可以将输入标签包裹在
<span>
,并仅在用户选择“是”(即booleanVariable
为true
时显示它
Try like this: 尝试这样:
<p class="input-label">
<span *ngIf="booleanVariable"> Some text </span>
</p>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.