Skip to content

Commit

Permalink
fix: wrong radio / checkbox behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jabali2004 committed Dec 18, 2021
1 parent f6d422b commit c28ad92
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<div class="form-control h-auto" *ngIf="dynamicControl">
<label class="mr-2" [for]="dynamicControl.formControlName"
*ngIf="dynamicControl.label">{{ dynamicControl.label }}</label>
<input [ngClass]="{'fullWidth': dynamicControl.fullWidth}" [id]="dynamicControl.formControlName"
[type]="dynamicControl.type || 'checkbox'" [formControl]="dynamicControl.formControl"
*ngIf="dynamicControl.formControl" [checked]="dynamicControl.formControl.value" [attr.disabled]="dynamicControl.disabled ? '' :
<input (change)="onChange($event)" [ngClass]="{'fullWidth': dynamicControl.fullWidth}"
[id]="dynamicControl.formControlName" [type]="dynamicControl.type || 'checkbox'"
[formControl]="dynamicControl.formControl" *ngIf="dynamicControl.formControl"
[attr.checked]="dynamicControl.formControl.value ? '' : null" [attr.disabled]="dynamicControl.disabled ? '' :
null">
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ export class CheckboxControlComponent extends BaseControlComponent {
}

ngOnInit(): void {}

public onChange($event: Event): void {
if ($event) {
const target = $event.target as HTMLInputElement;
this.dynamicControl.formControl.setValue(target.checked);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<div class="form-control h-auto" *ngIf="dynamicControl">
<label class="mr-2" [for]="dynamicControl.formControlName"
*ngIf="dynamicControl.label">{{ dynamicControl.label }}</label>
<input [ngClass]="{'fullWidth': dynamicControl.fullWidth}" [id]="dynamicControl.formControlName"
[type]="dynamicControl.type || 'radio'" [formControl]="dynamicControl.formControl"
*ngIf="dynamicControl.formControl" [checked]="dynamicControl.formControl.value" [attr.disabled]="dynamicControl.disabled ? '' :
<input (change)="onChange($event)" [ngClass]="{'fullWidth': dynamicControl.fullWidth}"
[id]="dynamicControl.formControlName" [type]="dynamicControl.type || 'radio'"
[formControl]="dynamicControl.formControl" *ngIf="dynamicControl.formControl"
[attr.checked]="dynamicControl.formControl.value ? '' : null" [attr.disabled]="dynamicControl.disabled ? '' :
null">
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ export class RadioControlComponent extends BaseControlComponent {
}

ngOnInit(): void {}

public onChange($event: Event): void {
if ($event) {
const target = $event.target as HTMLInputElement;
this.dynamicControl.formControl.setValue(target.checked);
}
}
}

0 comments on commit c28ad92

Please sign in to comment.