小编Ram*_*ona的帖子

Angular 2表单验证开始日期<=结束日期

我正在尝试添加验证,以便结束日期不能在开始日期之前.不幸的是我不知道该怎么做,到目前为止我在互联网上找不到任何有用的建议.我的表单看起来像这样:

editAndUpdateForm(tageler: Tageler) {
    this.tageler = tageler;
    this.tagelerForm = this.fb.group({
      title: [this.tageler.title, Validators.required],
      text: this.tageler.text,
      group: [[this.tageler.group], Validators.required],
      date_start: new Date(this.tageler.start).toISOString().slice(0, 10),
      date_end: new Date(this.tageler.end).toISOString().slice(0, 10),
      ...
    });
    this.tagelerForm.valueChanges
       .subscribe(data => this.onValueChanged(data));
    }
Run Code Online (Sandbox Code Playgroud)

到目前为止我的验证:

onValueChanged(data?: any) {
    if (!this.tagelerForm) {
      return;
    }
    const form = this.tagelerForm;

    for (const field in this.formErrors) {

    // clear previous error message (if any)
      this.formErrors[field] = '';
      const control = form.get(field);

      if (control && control.dirty && !control.valid) {
        const messages = this.validationMessages[field];
        for (const key …
Run Code Online (Sandbox Code Playgroud)

validation angular2-forms

12
推荐指数
3
解决办法
4万
查看次数

标签 统计

angular2-forms ×1

validation ×1