css - 具有自定义验证的 Angular 组件
问题描述
我有一个 Angular 5 组件,它基本上只是一个标签和输入
<div class="form-group">
<label for="wwid">WWID</label>
<input id="wwid" required ...lots of attrs...>
</div>
然后我使用 CSS 定义了一个样式:
.ng-invalid:not(form) {
border-left: 5px solid #a94442; /* red */
}
当该字段为空白时,我得到两个红色边框。我想要的输入字段上的一个,也是我不想要的标签右侧的一个。如何去除标签上的红线?
这是组件使用的实际完整 HTML。
<ng-template #listSelectionFormatter let-r="result">
<span>{{r.wwid}} - {{r.fullName}}</span>
</ng-template>
<div class="form-group">
<label *ngIf="labelText" for="wwid">
{{ labelText }}
<span *ngIf="isRequired"> <sup class="requiredIndicator">*</sup></span>
</label>
<!-- inputFormatter is the format for what is placed into the input field after choosing from the dropdown -->
<input id="wwid" type="text"
class="form-control"
placeholder="Search by WWID, IDSID, Name or Email"
(selectItem)="onWorkerSelected($event.item)"
(input)="onTextFieldChanged($event.target.value)"
[ngModel]="selectedWorker"
[ngbTypeahead]="search"
[inputFormatter]="selectedResultsFormatter"
[resultTemplate]="listSelectionFormatter"
[disabled]="disabled"
[required]="required"
/>
<span *ngIf="searching">searching…</span>
<div class="invalid-feedback" *ngIf="searchFailed">Lookup failed.</div>
</div>
如果需要的requiredIndicator
话,这只是我用来显示星号的旧样式,并使用了这个 CSS:
.requiredIndicator {
color: red;
font-size: larger;
vertical-align: baseline;
position: relative;
top: -0.1em;
}
解决方案
推荐阅读
- html - 使用锚标记的元素方向不正确
- php - 在电子商务项目中使用 laravel 从购物车中删除产品
- php - 在 php html 中使用表单过滤数据库表
- jquery - 当 ajax 请求在完成页面加载后拦截 ajax 调用,xhr 拦截器和 ajax 启动也不起作用
- keras - keras中通过时间源代码的LSTM反向传播
- python - 聚类过程中的参数错误
- java - GIF转PNG转换PNG转换后变得模糊java
- django - 如何在Django中按升序列出不同值的整数字段
- c++ - 为什么这个本地 QMultiMap 在修改时会分离?
- git - 难以推送到 github