Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nb-option ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'setDisabled: false'. Current value: 'setDisabled: true'. #1210

Closed
jagabs opened this issue Feb 2, 2019 · 2 comments · Fixed by #1329

Comments

@jagabs
Copy link

jagabs commented Feb 2, 2019

type is nb-select
<nb-select outline shape="rectangle"  placeholder="Transaction Type" formControlName="type" style="width: 100%">
              <nb-option value="Loan">Loan</nb-option>
              <nb-option value="Payment">Payment</nb-option>
</nb-select>


const typeValueChanges$ = this.transactionForm.controls['type'].valueChanges;
		typeValueChanges$.subscribe((value) => {
			if (value === 'Payment') {
				this.transactionForm.get("paymentType").setValue('Cash');
				this.transactionForm.get("paymentType").setValidators(Validators.required);
			} else {
				this.transactionForm.get("paymentType").setValue(null);
				this.transactionForm.get("paymentType").setValidators(null);
				this.transactionForm.get("paymentType").setErrors(null);
			}
			this.transactionForm.updateValueAndValidity();
		});

When i change the type to payment the first time, no error. Change to Loan and to payment again it gives me this error.

screen shot 2019-02-02 at 11 20 01 pm
screen shot 2019-02-02 at 11 20 17 pm

@QuantalDingo
Copy link

I had the same problem. There are some problems with destroying elements like nb-select and nb-checkbox because of value in control changes after nb-select destroyed. You can temporary change this.cd.detectChanges() in select.component.js on
if(!this.cd['destroyed']) { this.cd.detectChanges(); }

@yggg
Copy link
Contributor

yggg commented Mar 28, 2019

Thanks for reporting! Fix is planned for 3.4.2 (PR #1329).
For now you can prevent error by recreating control instead of setting new value.
Something like this:

if (value === 'Payment') {
  this.transactionForm.removeControl('paymentMethod');
  this.transactionForm.addControl('paymentMethod', new FormControl('Cash', Validators.required));
} else {
  this.transactionForm.removeControl('paymentMethod');
  this.transactionForm.addControl('paymentMethod', new FormControl(null));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants