Skip to content

Instantly share code, notes, and snippets.

@cezar-plescan
Created April 13, 2024 15:32
define isSaving form state
protected isSaveRequestInProgress = false;
protected get isSaveButtonDisabled() {
return !this.form.valid || this.isFormPristine || this.isSaveRequestInProgress;
}
protected get isResetButtonDisabled() {
return this.isFormPristine || this.isSaveRequestInProgress;
}
protected saveUserData() {
// set the saving flag
this.isSaveRequestInProgress = true;
// disable form controls
this.disableForm();
this.saveUseData$()
.pipe(
finalize(() => {
// clear the saving flag
this.isSaveRequestInProgress = false;
// enable form controls
this.enableForm();
}),
catchError(error => {
// ...
})
)
.subscribe((response) => {
// ...
})
}
private disableForm() {
Object.values(this.form.controls).forEach(control => {
control.disable()
})
}
private enableForm() {
Object.values(this.form.controls).forEach(control => {
control.enable()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment