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

关于应用 NZ 响应表单的BUG #134

Closed
myepoch opened this issue Aug 23, 2017 · 5 comments
Closed

关于应用 NZ 响应表单的BUG #134

myepoch opened this issue Aug 23, 2017 · 5 comments

Comments

@myepoch
Copy link

myepoch commented Aug 23, 2017

当文本框失去焦点的时候,预期文本框 不可编辑(但是disable 顺序在上起作用,disable顺序在下不起作用)
` <form nz-form [formGroup]="validateForm" (ngSubmit)="_submitForm()">
<input id="email" name="email" formControlName="email" (blur)="onIdCardChange(validateForm.controls)" class="form-control">

`

` ngOnInit() {
this.validateForm = this.fb.group({ // 初始化表单模型
email : [ '', [ Validators.email ] ]
});
}

public onIdCardChange (form: any): void { // 当页面文本框失去焦点时
// this.validateForm.get ('email').disable (); // 如果写在这,那么文本框 disable 起作用

this.validateForm = this.fb.group({
  email            : [ 'hello@nz-zorro.com', [ Validators.email ] ],
});

this.validateForm.get ('email').disable (); // 如果写在这,那么文本框 disable 不起作用

}`

@vthinkxie
Copy link
Member

@myepoch It seems that you are using original angular input form, it has noting todo with ng-zorro.

@create-share
Copy link
Contributor

create-share commented Aug 29, 2017

Hi.
I think it should be a bug.
A custom form control with 'disabled' attribute should implement the setDisabledState method of interface ControlValueAccessor, otherwise it can not be disabled when using a reactive form such as FormControl / FormGroup.

For example:
https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/src/components/input/nz-input.component.ts

export class NzInputComponent implements AfterContentInit, ControlValueAccessor {
  // ...

  // This function is called when the control status changes to or from "DISABLED".
  setDisabledState(isDisabled: boolean): void {
    this.nzDisabled = isDisabled;
  }
}

I search the components file. I found that many components are missing this hook.

@create-share
Copy link
Contributor

If confirmed as a bug. My pleasure to help to fix other components that implement ControlValueAccessor to be a custom form control.

@vthinkxie
Copy link
Member

@deart1mer Yes, nz-input and all other components such as nz-datepicker have not implement the setDisabledState yet, but this is not associate with this issue since @myepoch used input other than nz-input.

It is great that if you want to help us to patch all components with setDisabledState, thanks.

vthinkxie pushed a commit that referenced this issue Sep 4, 2017
* fix(module:input): fix disable bug in reactive form (#134)

* fix(module:switch): fix disable bug in reactive form

* fix(module:slider): fix disable bug in reactive form

* fix(module:select): fix disable bug in reactive form

* fix(module:input-number): fix disable bug in reactive form

* fix(module:timepicker): fix disable bug in reactive form

* fix(module:datepicker): fix disable bug in reactive form

* fix(module:rate): fix disable bug in reactive form

* fix(module:radio): fix radio-group disable bug in reactive form

* fix(module:checkbox): fix checkbox & checkbox-group disable bug in reactive form

* fix(module:cascader): fix cascader disable bug in reactive form
@lock
Copy link

lock bot commented Feb 19, 2019

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants