Skip to content

Commit

Permalink
fix: set value on checkbox and forms generic types
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoninoBonanno authored and astagi committed Jul 14, 2023
1 parent 698adfd commit 571f9b7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
import { ItAbstractFormComponent } from '../../../abstracts/abstract-form.component';
import { BooleanInput, isTrueBooleanInput } from '../../../utils/boolean-input';
import { AsyncPipe, NgIf, NgTemplateOutlet } from '@angular/common';
Expand All @@ -11,7 +11,7 @@ import { ReactiveFormsModule } from '@angular/forms';
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [NgIf, NgTemplateOutlet, ReactiveFormsModule, AsyncPipe]
})
export class ItCheckboxComponent extends ItAbstractFormComponent<boolean> implements OnInit {
export class ItCheckboxComponent extends ItAbstractFormComponent<boolean | null | undefined> implements OnInit, OnChanges {

/**
* If show checkbox as toggle
Expand Down Expand Up @@ -48,7 +48,16 @@ export class ItCheckboxComponent extends ItAbstractFormComponent<boolean> implem

override ngOnInit() {
super.ngOnInit();
this.markAsChecked();
}

ngOnChanges(changes: SimpleChanges) {
if (changes['checked']) {
this.markAsChecked();
}
}

private markAsChecked(): void {
if (this.control.value || this.checked === undefined) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { MarkMatchingTextPipe } from '../../../pipes/mark-matching-text.pipe';
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [NgIf, ReactiveFormsModule, TranslateModule, AsyncPipe, ItIconComponent, MarkMatchingTextPipe, NgTemplateOutlet, NgForOf]
})
export class ItInputComponent extends ItAbstractFormComponent<string | number> implements OnInit {
export class ItInputComponent extends ItAbstractFormComponent<string | number | null | undefined> implements OnInit {

/**
* The input type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { TranslateModule } from '@ngx-translate/core';
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [NgIf, ReactiveFormsModule, ItIconComponent, AsyncPipe, TranslateModule]
})
export class ItPasswordInputComponent extends ItAbstractFormComponent<string> implements OnInit, AfterViewInit {
export class ItPasswordInputComponent extends ItAbstractFormComponent<string | null | undefined> implements OnInit, AfterViewInit {

/**
* The field is required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { AsyncPipe, NgIf } from '@angular/common';
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [ReactiveFormsModule, NgIf, AsyncPipe]
})
export class ItRadioButtonComponent extends ItAbstractFormComponent<string | number | undefined> implements OnInit {
export class ItRadioButtonComponent extends ItAbstractFormComponent<string | number | null | undefined> implements OnInit {

/**
* The radio value
*/
@Input() value: string | number | undefined;
@Input() value: string | number | undefined | null;

/**
* If show radio inline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ItIconComponent } from '../../utils/icon/icon.component';
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [TranslateModule, NgForOf, ReactiveFormsModule, ItIconComponent]
})
export class ItRatingComponent extends ItAbstractFormComponent<number> implements OnInit, OnChanges {
export class ItRatingComponent extends ItAbstractFormComponent<number | null | undefined> implements OnInit, OnChanges {

/**
* The rating value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ReactiveFormsModule } from '@angular/forms';
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [NgIf, ReactiveFormsModule, AsyncPipe]
})
export class ItTextareaComponent extends ItAbstractFormComponent<string> {
export class ItTextareaComponent extends ItAbstractFormComponent<string | null | undefined> {

/**
* Textarea Rows
Expand Down

0 comments on commit 571f9b7

Please sign in to comment.