L
L
lzy2019-06-25 00:01:01
Angular
lzy, 2019-06-25 00:01:01

Why is Angular form not validating?

Hello, I created a form, it has a DatePicker, I use https://materializecss.com/pickers.html, the form works successfully, opens and selects the date and also inserts it into the input, but the problem is that Angular does not see the changes and thinks Input is still empty and asks for a date. But if you use the standard DatePicker from input type="date", then everything works.

<div class="input-field">
      <input
        type="text"
        id="preparationStartDate"
        formControlName="preparationStartDate"
        #preparationStartDate
        [ngClass]="{'invalid': form.get('preparationStartDate').invalid && form.get('preparationStartDate').touched}"
      >
      <label for="preparationStartDate">Начало</label>
    </div>

ngOnInit() {

    this.form = new FormGroup({
      preparationStartDate: new FormControl('', Validators.required)
    })
}

ngAfterViewInit() {
    this.preparationStartDate = MaterialService.initDatePicker(this.startRef, null)
  }

I'm new to Angular, can you please tell me how to fix the error so that after selecting a date through materialize datepicker, the form becomes valid?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question