new song form
This commit is contained in:
@@ -9,11 +9,13 @@ import { switchMap, tap } from 'rxjs/operators';
|
|||||||
export class EditSongService {
|
export class EditSongService {
|
||||||
constructor(private songsService: SongsService) {}
|
constructor(private songsService: SongsService) {}
|
||||||
|
|
||||||
public initEditForm(): FormGroup {
|
public initEditForm(attachSync: boolean): FormGroup {
|
||||||
const song = this.songsService.selectedSong.value;
|
const song = this.songsService.selectedSong.value;
|
||||||
const form = new FormGroup({
|
const form = new FormGroup({
|
||||||
ID: new FormControl(song.ID, { updateOn: 'blur' }),
|
Number: new FormControl(song.Number, {
|
||||||
Number: new FormControl(song.Number, { updateOn: 'blur' }),
|
updateOn: 'blur',
|
||||||
|
validators: [Validators.required, Validators.min(1)]
|
||||||
|
}),
|
||||||
Name: new FormControl(song.Name, {
|
Name: new FormControl(song.Name, {
|
||||||
updateOn: 'blur',
|
updateOn: 'blur',
|
||||||
validators: Validators.required
|
validators: Validators.required
|
||||||
@@ -28,13 +30,15 @@ export class EditSongService {
|
|||||||
Comments: new FormControl(song.Comments, { updateOn: 'blur' }),
|
Comments: new FormControl(song.Comments, { updateOn: 'blur' }),
|
||||||
});
|
});
|
||||||
|
|
||||||
const controls = Object.keys(form.controls);
|
if (attachSync) { this.attachSync(form, song); }
|
||||||
controls.forEach(control => {
|
|
||||||
form.controls[control].valueChanges.pipe(
|
|
||||||
switchMap(value => this.songsService.patch(song.ID, control, value))
|
|
||||||
).subscribe();
|
|
||||||
});
|
|
||||||
|
|
||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private attachSync(form: FormGroup, song: import("/Users/benjamin/src/wgenerator/WEB/src/app/models/song.model").Song) {
|
||||||
|
const controls = Object.keys(form.controls);
|
||||||
|
controls.forEach(control => {
|
||||||
|
form.controls[control].valueChanges.pipe(switchMap(value => this.songsService.patch(song.ID, control, value))).subscribe();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user