|
@@ -12,10 +12,12 @@ export class CheckbuttonGroupComponent extends GroupInputComponent implements On
|
|
|
firstControl: FormControl;
|
|
|
|
|
|
constructor(
|
|
|
- @Attribute('firstEnablesRest') private firstEnablesRest
|
|
|
+ @Attribute('firstEnablesRest') private firstEnablesRest,
|
|
|
+ @Attribute('allOrNone') private showAllOrNone
|
|
|
) {
|
|
|
super();
|
|
|
this.firstEnablesRest = firstEnablesRest === ''; // True if 'firstEnablesRest' exists as component attribute
|
|
|
+ this.showAllOrNone = showAllOrNone === ''; // True if 'firstEnablesRest' exists as component attribute
|
|
|
}
|
|
|
|
|
|
ngOnInit() {
|
|
@@ -23,18 +25,21 @@ export class CheckbuttonGroupComponent extends GroupInputComponent implements On
|
|
|
if (this.meta.firstEnablesRest) {
|
|
|
this.firstEnablesRest = this.meta.firstEnablesRest;
|
|
|
}
|
|
|
+ if (this.meta.showAllOrNone) {
|
|
|
+ this.showAllOrNone = this.meta.showAllOrNone;
|
|
|
+ }
|
|
|
if (this.firstEnablesRest) {
|
|
|
this.firstControl = this.formGroup.controls[this.controlNames[0]] as FormControl;
|
|
|
- this.childMeta[0].isDisabled = false;
|
|
|
- this.childMeta.slice(1).map(meta => { meta.isDisabled = !this.firstControl.value; return meta; });
|
|
|
+ this.childMetaArray[0].isDisabled = false;
|
|
|
+ this.childMetaArray.slice(1).map(meta => { meta.isDisabled = !this.firstControl.value; return meta; });
|
|
|
|
|
|
// Observe value changes on first control
|
|
|
this.firstControl.valueChanges.subscribe(val => {
|
|
|
- for (let i = 1; i < this.childMeta.length; i++) {
|
|
|
+ for (let i = 1; i < this.childMetaArray.length; i++) {
|
|
|
// NOTE: We reassign the input (array member) to trigger change detection (otherwise it doesn't run)
|
|
|
// See https://juristr.com/blog/2016/04/angular2-change-detection/
|
|
|
- this.childMeta[i] = {
|
|
|
- ...this.childMeta[1],
|
|
|
+ this.childMetaArray[i] = {
|
|
|
+ ...this.childMetaArray[1],
|
|
|
isDisabled: !val
|
|
|
};
|
|
|
}
|
|
@@ -42,4 +47,15 @@ export class CheckbuttonGroupComponent extends GroupInputComponent implements On
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ selectAll(e: Event): false {
|
|
|
+ this.controlNames.forEach(c => this.formGroup.get(c).setValue(this.meta.meta[c].value));
|
|
|
+ (e.target as HTMLLinkElement).blur();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ selectNone(e: Event): false {
|
|
|
+ this.controlNames.forEach(c => this.formGroup.get(c).setValue(null));
|
|
|
+ (e.target as HTMLLinkElement).blur();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|