Skip to content

Commit

Permalink
fix(datepicker, radio): always call touched callback (#2026)
Browse files Browse the repository at this point in the history
  • Loading branch information
yggg committed Oct 22, 2019
1 parent 978a45c commit d3a8e44
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,8 @@ export class NbDatepickerDirective<D> implements OnDestroy, ControlValueAccessor
fromEvent(this.input, 'blur').pipe(
filter(() => !this.picker.isShown && this.document.activeElement !== this.input),
),
).pipe(
takeWhile(() => this.alive),
take(1),
).subscribe(() => this.onTouched());
).pipe(takeWhile(() => this.alive))
.subscribe(() => this.onTouched());
}

protected writePicker(value: D) {
Expand Down
13 changes: 3 additions & 10 deletions src/framework/theme/components/radio/radio-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { isPlatformBrowser } from '@angular/common';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { fromEvent, merge } from 'rxjs';
import { filter, switchMap, take, takeUntil, takeWhile } from 'rxjs/operators';
import { filter, switchMap, takeUntil, takeWhile } from 'rxjs/operators';
import { convertToBoolProperty } from '../helpers';
import { NB_DOCUMENT } from '../../theme.options';
import { NbRadioComponent } from './radio.component';
Expand Down Expand Up @@ -81,7 +81,6 @@ import { NbComponentStatus } from '../component-status';
export class NbRadioGroupComponent implements AfterContentInit, OnDestroy, ControlValueAccessor {

protected alive: boolean = true;
protected isTouched: boolean = false;
protected onChange = (value: any) => {};
protected onTouched = () => {};

Expand Down Expand Up @@ -232,7 +231,7 @@ export class NbRadioGroupComponent implements AfterContentInit, OnDestroy, Contr

protected subscribeOnRadiosBlur() {
const hasNoRadios = !this.radios || !this.radios.length;
if (!isPlatformBrowser(this.platformId) || this.isTouched || hasNoRadios) {
if (!isPlatformBrowser(this.platformId) || hasNoRadios) {
return;
}

Expand All @@ -246,15 +245,9 @@ export class NbRadioGroupComponent implements AfterContentInit, OnDestroy, Contr
fromEvent<Event>(this.document, 'click'),
)),
filter(event => !hostElement.contains(event.target as Node)),
take(1),
takeUntil(this.radios.changes),
)
.subscribe(() => this.markTouched());
}

protected markTouched() {
this.isTouched = true;
this.onTouched();
.subscribe(() => this.onTouched());
}

protected updateStatus() {
Expand Down

0 comments on commit d3a8e44

Please sign in to comment.