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

Validate FormGroup với 1 vài control #27

Closed
TND195 opened this issue Oct 2, 2020 · 4 comments
Closed

Validate FormGroup với 1 vài control #27

TND195 opened this issue Oct 2, 2020 · 4 comments

Comments

@TND195
Copy link

TND195 commented Oct 2, 2020

Mình gặp 1 trouble như sau nhưng hiện tại chưa có hướng giải quyết:
Có 1 FormGroup gồm 3 FormControl: A, B, C.Mình viết hàm asyncValidators luôn cả FormGroup nhưng mình chỉ muốn validate khi chỉ có A,B thay đổi thôi.Còn C thì không.
Có cách nào mà không cần bỏ C ra hoặc tạo FormGroup riêng cho A với B không? Tại khi get Value ra đem lên BE hơi rắc rối.

Thanks.

@tntruong96
Copy link

trong hàm validator bạn có thể chọn ra fields mình muốn để check mà. bạn kham khảo thử chổ người ta check password match với nhau trong đây: https://codinglatte.com/posts/angular/cool-password-validation-angular/

@TND195
Copy link
Author

TND195 commented Oct 2, 2020

Nó chỉ set error thôi.Chứ mình thấy trong project khi thay đổi email nó vẫn chạy hàm validate của formGroup.Vậy nếu th async thì nó sẽ call api lên hệ thống

@trungvose
Copy link
Member

@TND195 Mình chưa gặp trường hợp này bao giờ nhưng đơn giản nhất là như bạn nói, tạo ra một formGroup riêng cho field A và B. Rồi khi submit form thì merge formGroup chứa A,B và C thành một object thôi. Nếu ko thì phải code hơi thủ công ở hàm async validator trước khi tạo request lên server validate

@TND195
Copy link
Author

TND195 commented Oct 4, 2020

Cảm ơn bạn.Tại mình muốn xem có giải pháp nào hay hơn không?Do nghiệp dự án gặp nhiều trường hợp thế này.Mình sợ sau này còn thêm check A, B,D thì khó bỏ trong group được.

@TND195 TND195 closed this as completed Oct 4, 2020
@TND195 TND195 reopened this Oct 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants