0
votes

Selecting a new Calendar value does not update the value in the formControlName

I tried setting the model property to a string, I also tried setting the dataType on the calendar to a string. To set the default value on the calendar from the model, I have to convert the value to a new date. Listening to onBlur also shows the old value, not the new value.

I am using Angular 7, Ionic 4 and PrimeNg 7.1

ngOnInit() {

  this.form = new FormGroup({
      dfrDate: new FormControl(null, {
        updateOn: 'blur',
        validators: [Validators.required]
      }),



<p-calendar  #dfrDateRef dataType="string"  showButtonBar="true" formControlName='dfrDate' [showIcon]="true" ></p-calendar>

I expect the form control value to update automatically, like all other form fields. I can get around this by using viewChild on form submission, but that would a pain to do for every date field in this app

1

1 Answers

0
votes

To check for changes, use the onSelect event, like so:

In view:

<p-calendar 
    [(ngModel)]="inputDate"
    (onSelect)="inputDateChanged()">
</p-calendar>

In controller:

public inputDateChanged(): void {
    // Do something with this.inputDate
}