How to throw an error if markdown editor left empty in the form?

183 views Asked by At

I have used a markdown editor in my angular HTML file form as follows:

        <td-text-editor class="full-width" formControlName="description"></td-text-editor>

In the form, if we leave the description empty, it should throw up an error. Any inputs?

1

There are 1 answers

0
Nico On BEST ANSWER

Just add a required validator to your formControl then you can show the errors for that formControl on your template

this.myform = new FormGroup({
'description': new FormControl(this.hero.power, Validators.required)
});

On your template

<input id="name" class="form-control"
      formControlName="description" required >

<div *ngIf="description.invalid && (description.dirty || description.touched)"
    class="alert alert-danger">

  <div *ngIf="name.errors.required">
    Description is required.
  </div>