Skip to content

Commit fc9fb2b

Browse files
authored
fix: "Save" button now immediately enabled for matching dialogs
closes #3231
1 parent 9929d03 commit fc9fb2b

File tree

2 files changed

+1
-28
lines changed

2 files changed

+1
-28
lines changed

src/app/core/form-dialog/dialog-buttons/dialog-buttons.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<button
22
mat-raised-button
33
color="accent"
4-
[disabled]="!canSave"
4+
[disabled]="!form.formGroup.valid"
55
(click)="save()"
66
angulartics2On="click"
77
[angularticsCategory]="entity?.getType()"

src/app/core/form-dialog/dialog-buttons/dialog-buttons.component.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import { EntityAbility } from "../../permissions/ability/entity-ability";
2121
import { UnsavedChangesService } from "../../entity-details/form/unsaved-changes.service";
2222
import { EntityActionsMenuComponent } from "../../entity-details/entity-actions-menu/entity-actions-menu.component";
2323
import { ViewComponentContext } from "../../ui/abstract-view/view-component-context";
24-
import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
2524

26-
@UntilDestroy()
2725
@Component({
2826
selector: "app-dialog-buttons",
2927
imports: [
@@ -50,7 +48,6 @@ export class DialogButtonsComponent<E extends Entity> implements OnInit {
5048
@Input() entity: E;
5149
@Input() form: EntityForm<E>;
5250
detailsRoute: string;
53-
canSave: boolean = false;
5451

5552
@Output() closeView = new EventEmitter<any>();
5653

@@ -82,11 +79,6 @@ export class DialogButtonsComponent<E extends Entity> implements OnInit {
8279
}
8380
this.initializeDetailsRouteIfAvailable();
8481
}
85-
this.form.formGroup.valueChanges
86-
.pipe(untilDestroyed(this))
87-
.subscribe(() => {
88-
this.canSave = this.hasFormValue();
89-
});
9082
}
9183

9284
private initializeDetailsRouteIfAvailable() {
@@ -132,23 +124,4 @@ export class DialogButtonsComponent<E extends Entity> implements OnInit {
132124
this.close();
133125
}
134126
}
135-
136-
/**
137-
* Checks if any control in the form has a non-empty value.
138-
* Returns true if at least one form control contains a value
139-
*/
140-
private hasFormValue(): boolean {
141-
return Object.values(this.form.formGroup.controls).some((ctrl) => {
142-
const val = ctrl.value;
143-
if (
144-
val === null ||
145-
val === undefined ||
146-
(Array.isArray(val) && val.length === 0) ||
147-
JSON.stringify(val) === "{}" ||
148-
(typeof val === "string" && val.trim().length === 0)
149-
)
150-
return false;
151-
else return true;
152-
});
153-
}
154127
}

0 commit comments

Comments
 (0)