【发布时间】:2019-07-04 11:02:31
【问题描述】:
我正在尝试在我的模板驱动表单上以角度 7 实现 kendo-dropdownlist 的必填字段验证。如果您可以看到我正在循环并生成一个动态表,该表在每一行中都有 kendo 下拉列表。如果未选中,我需要突出显示下拉菜单。我试图用表单标签将我的 div 括起来,以为当用户按下提交时我可以处理它,但我认为这更多的是在 kendo 中设置。有人可以告诉我如何做到这一点。到目前为止,我看到的所有示例都是基于 jquery 的。
这里是堆栈闪电战 https://stackblitz.com/edit/angular-4v2k8f
HTML
form name="form" (ngSubmit)="f.form.valid && createDocument()" #f="ngForm" novalidate>
<div class="center" class="file-upload-wrapper">
<ngx-file-drop dropZoneLabel="Drop files here" dropZoneClassName="file-drop" multiple="true"
(onFileDrop)="dropped($event)" (onFileOver)="fileOver($event)" (onFileLeave)="fileLeave($event)">
<ng-template ngx-file-drop-content-tmp let-openFileSelector="openFileSelector">
<button type="button" (click)="openFileSelector()">Drop Files to Upload</button>
</ng-template>
</ngx-file-drop>
<div class="upload-table">
<table id="table1" class="center">
<tbody class="upload-name-style">
<tr *ngFor="let item of files; let i=index">
<td> <input kendoTextBox [(ngModel)]="item.relativePath" style="width: 350px" /></td>
<td>
<kendo-dropdownlist style="width:350px" [(ngModel)]="item.selectedDocumentItem"
[data]="DocumentTypes" [defaultItem]="defaultItem" [filterable]="false" textField="Name"
valueField="Id">
</kendo-dropdownlist>
</td>
<td>
<kendo-datepicker style="width: 200px" [format]="'dd MMM, yyyy'"
[(ngModel)]="item.selectedDate"></kendo-datepicker>
</td>
<td> <button class="btn btn-default" (click)="deleteRow(i)"><i class="fa fa-trash"></i>Delete
</button></td>
</tr>
</tbody>
</table>
</div>
<div class="wrapper">
<button *ngIf="files.length > 0" type="submit" class="btn btn-primary btn-upload">upload</button>
</div>
</div>
</form>
组件
public createDocument() {
this.files.forEach(element => {
this.uploadDocument = <IDocument>{
id: 5508,
documentTypeId: element.selectedDocumentItem.Id ,
name: element.relativePath,
documentDate: element.selectedDate
};
});
}
【问题讨论】:
-
你能提供一个stackblitz的例子吗?
-
这里是stackblitz stackblitz.com/edit/angular-4v2k8f
-
isRequired 呢?查看文档:telerik.com/kendo-angular-ui/components/dropdowns/dropdownlist/…