|
@@ -1,43 +1,28 @@
|
|
-import { Component, Attribute, OnInit, Input } from '@angular/core';
|
|
|
|
-import { ControlContainer, FormGroup, FormControl } from '@angular/forms';
|
|
|
|
-import { CustomInputComponent } from './../../_abstract/custom-input.component';
|
|
|
|
|
|
+import { Component, Attribute, OnInit } from '@angular/core';
|
|
|
|
+import { FormControl } from '@angular/forms';
|
|
|
|
+import { GroupInputComponent } from './../../_abstract/group-input.component';
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
selector: 'app-checkbutton-group',
|
|
selector: 'app-checkbutton-group',
|
|
templateUrl: './checkbutton-group.component.html',
|
|
templateUrl: './checkbutton-group.component.html',
|
|
styleUrls: ['./checkbutton-group.component.scss']
|
|
styleUrls: ['./checkbutton-group.component.scss']
|
|
})
|
|
})
|
|
-export class CheckbuttonGroupComponent /* extends CustomInputComponent */ implements OnInit {
|
|
|
|
|
|
+export class CheckbuttonGroupComponent extends GroupInputComponent implements OnInit {
|
|
|
|
|
|
- @Input()
|
|
|
|
- control: FormGroup;
|
|
|
|
-
|
|
|
|
- @Input()
|
|
|
|
- meta;
|
|
|
|
-
|
|
|
|
- formGroup: FormGroup;
|
|
|
|
firstControl: FormControl;
|
|
firstControl: FormControl;
|
|
- childMeta: Array<StringMap>;
|
|
|
|
- controlNames: Array<string>;
|
|
|
|
|
|
|
|
constructor(
|
|
constructor(
|
|
- private cc: ControlContainer,
|
|
|
|
@Attribute('firstEnablesRest') private firstEnablesRest
|
|
@Attribute('firstEnablesRest') private firstEnablesRest
|
|
) {
|
|
) {
|
|
- // super();
|
|
|
|
|
|
+ super();
|
|
this.firstEnablesRest = firstEnablesRest === ''; // True if 'firstEnablesRest' exists as component attribute
|
|
this.firstEnablesRest = firstEnablesRest === ''; // True if 'firstEnablesRest' exists as component attribute
|
|
- console.log('firstEnablesRest', this.firstEnablesRest);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
ngOnInit() {
|
|
ngOnInit() {
|
|
- console.log('************************');
|
|
|
|
- this.formGroup = this.control as FormGroup;
|
|
|
|
- // this.formGroup = this.cc.control as FormGroup;
|
|
|
|
- this.childMeta = Object.values(this.meta.meta); // Metadata array or all controls in group
|
|
|
|
- console.log(Array.isArray(this.childMeta));
|
|
|
|
- this.controlNames = Object.keys(this.formGroup.controls);
|
|
|
|
- // this.controlNames = Object.keys(this.cc.control.value);
|
|
|
|
- console.log(this.controlNames);
|
|
|
|
|
|
+ super.ngOnInit();
|
|
|
|
+ if (this.meta.firstEnablesRest) {
|
|
|
|
+ this.firstEnablesRest = this.meta.firstEnablesRest;
|
|
|
|
+ }
|
|
if (this.firstEnablesRest) {
|
|
if (this.firstEnablesRest) {
|
|
this.firstControl = this.formGroup.controls[this.controlNames[0]] as FormControl;
|
|
this.firstControl = this.formGroup.controls[this.controlNames[0]] as FormControl;
|
|
this.childMeta[0].isDisabled = false;
|
|
this.childMeta[0].isDisabled = false;
|
|
@@ -46,7 +31,8 @@ export class CheckbuttonGroupComponent /* extends CustomInputComponent */ implem
|
|
// Observe value changes on first control
|
|
// Observe value changes on first control
|
|
this.firstControl.valueChanges.subscribe(val => {
|
|
this.firstControl.valueChanges.subscribe(val => {
|
|
for (var i = 1; i < this.childMeta.length; i++) {
|
|
for (var i = 1; i < this.childMeta.length; i++) {
|
|
- // NOTE: We rassign input to trigger change detection
|
|
|
|
|
|
+ // NOTE: We rassign 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[i] = {
|
|
...this.childMeta[1],
|
|
...this.childMeta[1],
|
|
isDisabled: !val
|
|
isDisabled: !val
|