Skip to content

Commit

Permalink
fix(material): rely on checkbox change input instead of formly attr (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aitboudad committed Jul 11, 2020
1 parent ffad0db commit eaa66ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/material/checkbox/src/checkbox.type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, ViewChild } from '@angular/core';
import { FieldType } from '@ngx-formly/material/form-field';
import { MatCheckbox } from '@angular/material/checkbox';
import { MatCheckbox, MatCheckboxChange } from '@angular/material/checkbox';

@Component({
selector: 'formly-field-mat-checkbox',
Expand All @@ -11,6 +11,7 @@ import { MatCheckbox } from '@angular/material/checkbox';
[required]="to.required"
[formlyAttributes]="field"
[tabindex]="to.tabindex"
(change)="change($event)"
[indeterminate]="to.indeterminate && formControl.value === null"
[color]="to.color"
[labelPosition]="to.align || to.labelPosition">
Expand All @@ -36,4 +37,10 @@ export class FormlyFieldCheckbox extends FieldType {
this.checkbox.focus();
super.onContainerClick(event);
}

change($event: MatCheckboxChange) {
if (this.to.change) {
this.to.change(this.field, $event);
}
}
}
11 changes: 9 additions & 2 deletions src/material/radio/src/radio.type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, ViewChild, AfterViewInit, OnDestroy } from '@angular/core';
import { FieldType } from '@ngx-formly/material/form-field';
import { MatRadioGroup } from '@angular/material/radio';
import { MatRadioGroup, MatRadioChange } from '@angular/material/radio';
import { ɵwrapProperty as wrapProperty } from '@ngx-formly/core';

@Component({
Expand All @@ -10,7 +10,8 @@ import { ɵwrapProperty as wrapProperty } from '@ngx-formly/core';
[formControl]="formControl"
[formlyAttributes]="field"
[required]="to.required"
[tabindex]="to.tabindex">
[tabindex]="to.tabindex"
(change)="change($event)">
<mat-radio-button *ngFor="let option of to.options | formlySelectOptions:field | async; let i = index;"
[id]="id + '_' + i"
[color]="to.color"
Expand Down Expand Up @@ -52,4 +53,10 @@ export class FormlyFieldRadio extends FieldType implements AfterViewInit, OnDest
ngOnDestroy() {
this.focusObserver && this.focusObserver();
}

change($event: MatRadioChange) {
if (this.to.change) {
this.to.change(this.field, $event);
}
}
}

0 comments on commit eaa66ed

Please sign in to comment.