Skip to content

Commit

Permalink
Merge branch 'dtrpoc'
Browse files Browse the repository at this point in the history
  • Loading branch information
venkateshr06 committed Jun 14, 2024
2 parents e3f5b06 + 2ce9a46 commit cb8708e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
11 changes: 11 additions & 0 deletions projects/angular/src/forms/common/wrapped-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class WrappedFormControl<W extends DynamicWrapper> implements OnInit, DoC
private _containerInjector: Injector;
private differs: KeyValueDiffers;
private differ: KeyValueDiffer<any, any>;
private additionalDiffer = new Map<NgControl, KeyValueDiffer<any, any>>();
private ngControl: NgControl | null;

// I lost way too much time trying to make this work without injecting the ViewContainerRef and the Injector,
Expand Down Expand Up @@ -113,6 +114,10 @@ export class WrappedFormControl<W extends DynamicWrapper> implements OnInit, DoC
}
}

private get hasAdditionalControls() {
return this.additionalDiffer.size > 0;
}

ngOnInit() {
this._containerInjector = new HostWrapper(this.wrapperType, this.vcr, this.index);
this.controlIdService = this._containerInjector.get(ControlIdService);
Expand All @@ -136,12 +141,18 @@ export class WrappedFormControl<W extends DynamicWrapper> implements OnInit, DoC
} else {
this.ngControl = this.ngControlService.getControl();
this.ngControlService.addAdditionalControl(this._ngControl);
this.additionalDiffer.set(this._ngControl, this.differs.find(this._ngControl).create());
}
}
}

ngDoCheck() {
this.triggerDoCheck(this.differ, this.ngControl);
if (this.hasAdditionalControls) {
for (const [ngControl, differ] of this.additionalDiffer) {
this.triggerDoCheck(differ, ngControl);
}
}
}

triggerDoCheck(differ, ngControl) {
Expand Down
24 changes: 13 additions & 11 deletions projects/angular/src/forms/datepicker/date-input-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,19 @@ export class ClrDateInputBase extends WrappedFormControl<ClrDateContainer> imple
* if either of the field gets updated
*/
protected validateDateRange() {
const primaryControl = this.ngControlService?.getControl();
const additionalControls = this.ngControlService?.getAdditionalControls();
const isValid = this.dateNavigationService.selectedDay?.isBefore(this.dateNavigationService.selectedEndDay, true);
if (
isValid &&
(primaryControl?.hasError('range') || additionalControls?.some(control => control.hasError('range')))
) {
primaryControl.control?.updateValueAndValidity();
additionalControls.forEach((ngControl: NgControl) => {
ngControl?.control?.updateValueAndValidity();
});
if (this.dateNavigationService.isRangePicker) {
const primaryControl = this.ngControlService?.getControl();
const additionalControls = this.ngControlService?.getAdditionalControls();
const isValid = this.dateNavigationService.selectedDay?.isBefore(this.dateNavigationService.selectedEndDay, true);
if (
isValid &&
(primaryControl?.hasError('range') || additionalControls?.some(control => control.hasError('range')))
) {
primaryControl.control?.updateValueAndValidity();
additionalControls.forEach((ngControl: NgControl) => {
ngControl?.control?.updateValueAndValidity();
});
}
}
}

Expand Down

0 comments on commit cb8708e

Please sign in to comment.