Skip to content

Instantly share code, notes, and snippets.

@dpalou
Created January 11, 2024 16:21
Show Gist options
  • Save dpalou/a55ec47fb225318b3e7fb4f612109b32 to your computer and use it in GitHub Desktop.
Save dpalou/a55ec47fb225318b3e7fb4f612109b32 to your computer and use it in GitHub Desktop.
// Form variables.
descriptionControl: FormControl<string>;
form!: FormGroup<{
name: FormControl<string>;
timestart: FormControl<string>;
eventtype: FormControl<AddonCalendarEventType | null>;
categoryid: FormControl<number | null>;
courseid: FormControl<number>;
groupcourseid: FormControl<number | null>;
groupid: FormControl<number | null>;
description: FormControl<string>;
location: FormControl<string>;
duration: FormControl<number>;
timedurationuntil: FormControl<string>;
timedurationminutes: FormControl<number | null>;
repeat: FormControl<boolean>;
repeats: FormControl<number>;
repeateditall: FormControl<number>;
}>;
// Remove all form init logic from constructor and ngOnInit, and put this instead in ngOnInit:
this.form = new FormGroup({
name: new FormControl('', { validators: Validators.required, nonNullable: true }),
timestart: new FormControl(currentDate, { validators: Validators.required, nonNullable: true }),
eventtype: new FormControl<AddonCalendarEventType | null>(null, Validators.required),
categoryid: new FormControl<number | null>(null),
courseid: new FormControl(this.courseId, { nonNullable: true }),
groupcourseid: new FormControl<number | null>(null),
groupid: new FormControl<number | null>(null),
description: this.descriptionControl,
location: new FormControl('', { nonNullable: true }),
duration: new FormControl(0, { nonNullable: true }),
timedurationuntil: new FormControl(currentDate, { nonNullable: true }),
timedurationminutes: new FormControl<number | null>(null),
repeat: new FormControl(false, { nonNullable: true }),
repeats: new FormControl(1, { nonNullable: true }),
repeateditall: new FormControl(1, { nonNullable: true }),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment