Skip to content

Commit aebb339

Browse files
committed
Updated fix for the clear checkbox and radio button
1 parent a52df9c commit aebb339

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/ui-kit/form-controls/checkbox/checkbox.component.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Input,
55
Output,
66
EventEmitter,
7+
ChangeDetectorRef,
78
ViewChild
89
} from '@angular/core';
910
import {
@@ -77,20 +78,17 @@ export class SamCheckboxComponent implements ControlValueAccessor {
7778
*/
7879
@Input() id: string;
7980

80-
public optionChange:string;
81+
public optionChange: string;
8182

82-
public optionId:string;
83-
84-
85-
83+
public optionId: string;
8684
/**
8785
* Deprecated, Event emitted when the model value changes
8886
*/
8987
@Output() modelChange: EventEmitter<any> = new EventEmitter<any>();
9088

9189
@Output() optionSelected: EventEmitter<any> = new EventEmitter<any>();
9290

93-
@ViewChild(FieldsetWrapper, {static: true})
91+
@ViewChild(FieldsetWrapper, { static: true })
9492
public wrapper: FieldsetWrapper;
9593
activeOptions = 0;
9694
/*
@@ -103,7 +101,7 @@ export class SamCheckboxComponent implements ControlValueAccessor {
103101
onChange: any = (c) => undefined;
104102

105103
onTouched: any = () => undefined;
106-
104+
107105
get value() {
108106
return this.model;
109107
}
@@ -114,7 +112,7 @@ export class SamCheckboxComponent implements ControlValueAccessor {
114112
this.onTouched();
115113
}
116114

117-
constructor(protected samFormService: SamFormService) {}
115+
constructor(protected samFormService: SamFormService, private cdr: ChangeDetectorRef) { }
118116

119117
ngOnInit() {
120118
// initialize the order lookup map
@@ -148,17 +146,18 @@ export class SamCheckboxComponent implements ControlValueAccessor {
148146
}
149147
}
150148
this.model = returnVal;
149+
this.cdr.detectChanges();
151150
this.setSelectAllCheck();
152151
}
153152

154-
setSelectAllCheck(){
153+
setSelectAllCheck() {
155154
let activeOptionsNum = 0;
156-
this.options.forEach(val=>{
157-
if(!val.disabled){
155+
this.options.forEach(val => {
156+
if (!val.disabled) {
158157
activeOptionsNum++;
159158
}
160159
});
161-
this.activeOptions=activeOptionsNum;
160+
this.activeOptions = activeOptionsNum;
162161
}
163162

164163
// Give the check all label a name for screen readers
@@ -216,8 +215,8 @@ export class SamCheckboxComponent implements ControlValueAccessor {
216215
emitModel() {
217216

218217
this.modelChange.emit(this.model);
219-
220-
this.optionSelected.emit({model : this.model, selected: this.optionChange, id: this.optionId});
218+
219+
this.optionSelected.emit({ model: this.model, selected: this.optionChange, id: this.optionId });
221220
}
222221

223222
registerOnChange(fn) {

src/ui-kit/form-controls/radiobutton/radiobutton.component.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
Validators,
1717
ValidatorFn
1818
} from '@angular/forms';
19-
import {SamFormService} from '../../form-service';
19+
import { SamFormService } from '../../form-service';
2020

2121
/**
2222
* The <sam-radio-button> component is a set of checkboxes compliant with
@@ -31,11 +31,11 @@ import {SamFormService} from '../../form-service';
3131
multi: true
3232
}]
3333
})
34-
export class SamRadioButtonComponent {
34+
export class SamRadioButtonComponent {
3535
/**
3636
* Sets the bound value of the component
3737
*/
38-
@Input() public model: string|number|symbol;
38+
@Input() public model: string | number | symbol;
3939
/**
4040
* Sets the array of checkbox values and labels (see OptionsType)
4141
*/
@@ -69,12 +69,12 @@ export class SamRadioButtonComponent {
6969
*/
7070
@Output() public modelChange: EventEmitter<any> = new EventEmitter<any>();
7171

72-
@ViewChild(FieldsetWrapper, {static: true}) public wrapper: FieldsetWrapper;
72+
@ViewChild(FieldsetWrapper, { static: true }) public wrapper: FieldsetWrapper;
7373

7474
public disabled = undefined;
7575

7676

77-
constructor(private cdr: ChangeDetectorRef) {}
77+
constructor(private cdr: ChangeDetectorRef) { }
7878

7979
public ngOnInit() {
8080
if (!this.name) {
@@ -117,5 +117,6 @@ export class SamRadioButtonComponent {
117117

118118
public writeValue(value) {
119119
this.model = value;
120+
this.cdr.detectChanges();
120121
}
121122
}

0 commit comments

Comments
 (0)