Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Unable to change month and first click isn't registered when directive uses formControlName for Angular 15 #618

Open
mwgriffiths88 opened this issue Dec 12, 2022 · 4 comments

Comments

@mwgriffiths88
Copy link

mwgriffiths88 commented Dec 12, 2022

I'm using Angular 15, and I have a control that looks like this:

<form [formGroup]="form">
  <input
    formControlName="datetime"
    [dpDayPicker]="config"
    mode="daytime"
    theme="dp-material dp-main" />
</form>

There are two symptoms (seems to be across all browsers):

  • The first click is never made when the picker opens for the first time.
  • Unable to change the month.

https://stackblitz.com/edit/angular-ivy-fayr91?file=src/app/hello.component.ts

@mwgriffiths88 mwgriffiths88 changed the title Directive: First click isn't registered when bound via formControlName for Angular 15 Bug: First click isn't registered when directive uses formControlName for Angular 15 Dec 12, 2022
@mwgriffiths88 mwgriffiths88 changed the title Bug: First click isn't registered when directive uses formControlName for Angular 15 Bug: Unable to change month and first click isn't registered when directive uses formControlName for Angular 15 Dec 12, 2022
@HimanshuAgrahari07
Copy link
Contributor

I was checking this issue and i found something strange

When we first declare the value and return it from the same getter, it works

https://stackblitz.com/edit/angular-ivy-cbn2yw?file=src/app/hello.component.ts

Although i could not able to debug the reason behind this

@vlio20
Copy link
Owner

vlio20 commented Dec 13, 2022

I hope to have a look into it this weekend

@vlio20 vlio20 closed this as completed Dec 13, 2022
@vlio20 vlio20 reopened this Dec 13, 2022
@HimanshuAgrahari07
Copy link
Contributor

When we return it from a function (It doesn't work as expected)

@Component({
  selector: 'hello',
  template: `
    <form [formGroup]="form">
      <input
        formControlName="datetime"
        [dpDayPicker]="config()"
        mode="daytime"
        theme="dp-material dp-main" />
    </form>`,
  styles: [`h1 { font-family: Lato; }`],
})
export class HelloComponent implements OnInit {
  form!: FormGroup;

  config(): IDatePickerDirectiveConfig {
    return {
      minutesInterval: 5,
      firstDayOfWeek: 'mo',
      format: 'DD-MM-YYYY H:mm',
    };;
  }

  ngOnInit(): void {
    this.form = new FormGroup({
      datetime: new FormControl(null),
    });
  }
}

When we have an object created already, and we just have to return (it works)

  private _config: IDatePickerDirectiveConfig = {
    minutesInterval: 5,
    firstDayOfWeek: 'mo',
    format: 'DD-MM-YYYY H:mm',
  };

  config(): IDatePickerDirectiveConfig {
    return this._config;
  }

@HimanshuAgrahari07
Copy link
Contributor

I assume there is some kind of horse condition here [creating object ref and then return vs just returning the ref for already created object]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants