-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: created custom form input for boolean values (#1715)
closes #1683 Co-authored-by: Sebastian <sebastian.leidig@gmail.com>
- Loading branch information
1 parent
c417fe7
commit 058c3a9
Showing
12 changed files
with
118 additions
and
20 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
src/app/core/configurable-enum/basic-autocomplete/basic-autocomplete.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...ity-utils/dynamic-form-components/edit-boolean/boolean-input/boolean-input.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<mat-checkbox | ||
[disabled]="disabled" | ||
[(ngModel)]="value" | ||
(change)="onChange($event.checked)" | ||
>{{ placeholder }}</mat-checkbox> |
3 changes: 3 additions & 0 deletions
3
...ity-utils/dynamic-form-components/edit-boolean/boolean-input/boolean-input.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
app-boolean-input label { | ||
font-size: initial | ||
} |
23 changes: 23 additions & 0 deletions
23
...-utils/dynamic-form-components/edit-boolean/boolean-input/boolean-input.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { BooleanInputComponent } from './boolean-input.component'; | ||
|
||
describe('BooleanInputComponent', () => { | ||
let component: BooleanInputComponent; | ||
let fixture: ComponentFixture<BooleanInputComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ BooleanInputComponent ] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(BooleanInputComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
55 changes: 55 additions & 0 deletions
55
...ntity-utils/dynamic-form-components/edit-boolean/boolean-input/boolean-input.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
Component, | ||
ElementRef, | ||
Optional, | ||
Self, | ||
ViewChild, | ||
ViewEncapsulation, | ||
} from "@angular/core"; | ||
import { CustomFormControlDirective } from "../../../../../configurable-enum/basic-autocomplete/custom-form-control.directive"; | ||
import { MatCheckbox, MatCheckboxModule } from "@angular/material/checkbox"; | ||
import { | ||
FormGroupDirective, | ||
FormsModule, | ||
NgControl, | ||
NgForm, | ||
} from "@angular/forms"; | ||
import { MatFormFieldControl } from "@angular/material/form-field"; | ||
import { ErrorStateMatcher } from "@angular/material/core"; | ||
|
||
@Component({ | ||
selector: "app-boolean-input", | ||
standalone: true, | ||
imports: [MatCheckboxModule, FormsModule], | ||
providers: [ | ||
{ provide: MatFormFieldControl, useExisting: BooleanInputComponent }, | ||
], | ||
templateUrl: "./boolean-input.component.html", | ||
styleUrls: ["./boolean-input.component.scss"], | ||
encapsulation: ViewEncapsulation.None, | ||
}) | ||
export class BooleanInputComponent extends CustomFormControlDirective<boolean> { | ||
@ViewChild(MatCheckbox, { static: true }) inputElement: MatCheckbox; | ||
|
||
constructor( | ||
elementRef: ElementRef<HTMLElement>, | ||
errorStateMatcher: ErrorStateMatcher, | ||
@Optional() @Self() ngControl: NgControl, | ||
@Optional() parentForm: NgForm, | ||
@Optional() parentFormGroup: FormGroupDirective | ||
) { | ||
super( | ||
elementRef, | ||
errorStateMatcher, | ||
ngControl, | ||
parentForm, | ||
parentFormGroup | ||
); | ||
} | ||
|
||
onContainerClick(event: MouseEvent) { | ||
if ((event.target as Element).tagName.toLowerCase() != "mat-checkbox") { | ||
this.inputElement.focus(); | ||
} | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...-components/entity-utils/dynamic-form-components/edit-boolean/edit-boolean.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<div [formGroup]="parent" class="mat-checkbox-wrapper"> | ||
<mat-checkbox [formControlName]="formControlName">{{ label }}</mat-checkbox> | ||
</div> | ||
<mat-form-field> | ||
<app-boolean-input [formControl]="formControl" [placeholder]="label"></app-boolean-input> | ||
</mat-form-field> |
4 changes: 4 additions & 0 deletions
4
...-components/entity-utils/dynamic-form-components/edit-boolean/edit-boolean.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
app-edit-boolean .mat-mdc-form-field-infix { | ||
padding-top: 12px !important; | ||
padding-bottom: 0 !important; | ||
} |
9 changes: 6 additions & 3 deletions
9
...ty-components/entity-utils/dynamic-form-components/edit-boolean/edit-boolean.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import { Component } from "@angular/core"; | ||
import { Component, ViewEncapsulation } from "@angular/core"; | ||
import { EditComponent } from "../edit-component"; | ||
import { DynamicComponent } from "../../../../view/dynamic-components/dynamic-component.decorator"; | ||
import { ReactiveFormsModule } from "@angular/forms"; | ||
import { MatCheckboxModule } from "@angular/material/checkbox"; | ||
import { MatFormFieldModule } from "@angular/material/form-field"; | ||
import { BooleanInputComponent } from "./boolean-input/boolean-input.component"; | ||
|
||
@DynamicComponent("EditBoolean") | ||
@Component({ | ||
selector: "app-edit-boolean", | ||
templateUrl: "./edit-boolean.component.html", | ||
imports: [ReactiveFormsModule, MatCheckboxModule], | ||
styleUrls: ["./edit-boolean.component.scss"], | ||
imports: [ReactiveFormsModule, MatFormFieldModule, BooleanInputComponent], | ||
standalone: true, | ||
encapsulation: ViewEncapsulation.None, | ||
}) | ||
export class EditBooleanComponent extends EditComponent<boolean> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters