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

Using nb-checkbox in reactive form with disabled set to true #296

Closed
1 of 2 tasks
ohgasauraus opened this issue Mar 14, 2018 · 0 comments
Closed
1 of 2 tasks

Using nb-checkbox in reactive form with disabled set to true #296

ohgasauraus opened this issue Mar 14, 2018 · 0 comments

Comments

@ohgasauraus
Copy link

Issue type

I'm submitting a ... (check one with "x")

  • bug report
  • feature request

Issue description

Current behavior:

When I set disabled via FormGroup Controls, checkbox does not get disabled (missing setDisabledState)
When I manually set disabled via checkbox itself, i will get the following warning:

It looks like you're using the disabled attribute with a reactive form directive. If you set disabled to true
when you set up this control in your component class, the disabled attribute will actually be set in the DOM for
you. We recommend using this approach to avoid 'changed after checked' errors.

  Example: 
  form = new FormGroup({
    first: new FormControl({value: 'Nancy', disabled: true}, Validators.required),
    last: new FormControl('Drew', Validators.required)
  });

Expected behavior:

Setting disabled in the FormGroup Controls, checkbox should be rendered disabled.

Steps to reproduce:

See code snippet below:
component.ts
this.form = formbuilder.group({"myCheckbox": [{value: true, disabled:true}]});

component.html

<div [formGroup]="form">
  <nb-checkbox formControlName="myCheckbox">Disabled Checkbox</nb-checkbox>
</div>

Related code:

Add in setDisabledState into checkbox.component.ts as follow to fix this issue.

  setDisabledState(isDisabled:boolean) {
    this.disabled= isDisabled;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants