fingerpich / jalali-angular-datepicker

Highly configurable jalali (shamsi, khorshidi, persian) date picker built for Angular ( 2 or more ) applications
https://fingerpich.github.io/jalali-angular-datepicker/
MIT License
152 stars 61 forks source link

Cannot Update Datepicker's config min & max properties dynamically #85

Closed javidsapand closed 6 years ago

javidsapand commented 6 years ago

I am using [dpDayPicker] directive in angular 5 reactive forms, I have two date pickers one for start date and another for end date, I want to set the selected start date value as minimum end date value for end date picker, but setting the min property for end date picker config doesn't effect. here is the code:

startDatePickerConfig: IDatePickerConfig = {
    drops: 'down'
  };
  endDatePickerConfig: IDatePickerConfig = {
    drops: 'down'
  };

this.form = this.formBuilder.group({
      startDate: ['', Validators.required],
      endDate: ['', Validators.required],
    });

onStartDateChange() {
this.endDatePickerConfig.min = moment(this.form.controls.startDate.value, 'jYYYY-jMM-jDD');
}

<form [formGroup]="form" (ngSubmit)="onSubmit()" autocomplete="false" novalidate>
<div class="row">
<div class="col-md-6">
   <input type="text" class="form-control" formControlName="startDate" 
   [dpDayPicker]="startDatePickerConfig" (onChange)="onStartDateChange($event)"
   theme="dp-material"><i class="fa fa-calendar icon" aria-hidden="true"></i>
</div>
<div class="col-md-6">
   <input type="text" class="form-control" formControlName="endDate" 
   [dpDayPicker]="endDatePickerConfig" theme="dp-material">
   <i class="fa fa-calendar icon" aria-hidden="true"></i>
</div>
</div
</form>
javidsapand commented 6 years ago

@fingerpich or anyone else has any idea about this issue?

fingerpich commented 6 years ago

please make a demo in https://stackblitz.com/

javidsapand commented 6 years ago

Here is the demo https://stackblitz.com/edit/jalai-datepicker-max-min

fingerpich commented 6 years ago

use the following code

 onStartDateChange() {
    this.endDatePickerConfig = {...this.endDatePickerConfig, min: moment.from(this.testForm.controls.startDate.value,'fa', 'YYYY-MM-DD')}
  }

https://stackblitz.com/edit/jalai-datepicker-max-min-faaevr

fingerpich commented 6 years ago

`this.testForm.controls.startDate.value makes a string like '1387-2-31' and its not a standard way to make a jalali date.