angularangular-materialangular-formlyangular-material-datetimepicker

Access to Angular Formly Material Datepicker


I want to access the formly datepicker to make it close after selecting the year. But Im not able to access the datepicer object. Can please anybody help? Thank you!

  fieldsOfMyForm: FormlyFieldConfig[] = [
    {
      key: 'form',
      type: 'repeat',
      templateOptions: {
        addText: 'my form',

      },
      fieldArray: { fieldGroup: [ 
         {
            key: 'myyear',
            type: 'datepicker',
            templateOptions: {  
               datepickerOptions: { 
                    yearSelected: (( field: any, event: Moment) => { 
                       // here is the part where I want to calls something like datepicker.close(); 
                    }
                }
             }
       ] }

Solution

  • yearSelected: 
       ((field: FormlyFieldConfig, event: Moment, datepicker: MatDatepicker<Date>) => {         
          if (field.formControl) {
             field.formControl.setValue(new Date(event.calendar()));
             datepicker.close();
          }                  
       }
    )