ngneat / forms-manager

🦄 The Foundation for Proper Form Management in Angular
https://www.netbasal.com
MIT License
519 stars 29 forks source link

Support for mark* methods #12

Closed adrianriepl closed 4 years ago

adrianriepl commented 4 years ago

Would it make sense to add support the mark*() methods for a form or a control?

The methods could be called like formsManager.patchValue():

formsManager.markAllAsTouched('unboarding')

formsManager.markAsDirty('unboarding')

formsManager.markAsPending('unboarding')

formsManager.markAsPristine('unboarding')

formsManager.markAsTouched('unboarding')

formsManager.markAsUntouched('unboarding')
NetanelBasal commented 4 years ago

You're welcome to submit a PR.

adrianriepl commented 4 years ago

markAllAsTouched() is only available since Angular 8.0.0, so the project would need to be updated to at least this version. So there might be some more changes than just adding the above mentioned methods.

NetanelBasal commented 4 years ago

You can do it yourself without upgrading anything.

NetanelBasal commented 4 years ago

You can also add markAllAsDirty.

adrianriepl commented 4 years ago

Okay then I'll do it without upgrading it. I'll do a PR as soon as I find some time.

adrianriepl commented 4 years ago

I tried to implement the mark* methods but I am struggling a little bit. Maybe I made a mistake somewhere or have a misunderstanding how the library is structured. I have the following problem:

Can somebody help me out?

My fork

NetanelBasal commented 4 years ago

You can't call https://github.com/adrianriepl/forms-manager/blob/master/projects/ngneat/forms-manager/src/lib/forms-manager.ts#L261. As you said, it is only available since Angular 8.0.0.

NetanelBasal commented 4 years ago

You should do something like https://stackoverflow.com/a/44150793/7330592

adrianriepl commented 4 years ago

I forked the library after the last commit (where it was changed to Angular 9.1.11) so it should be available already or am I not seeing something?

NetanelBasal commented 4 years ago

You are right. When do you see the error?

adrianriepl commented 4 years ago

You will see the error when you click on the save button in the demo application. Here I call this.manager.markAllAsTouched('stepOne').

https://github.com/adrianriepl/forms-manager/blob/b6751ba9af2569928439316823d9ef758bac9175/src/app/demo/demo.component.ts#L50

NetanelBasal commented 4 years ago

I'll check it later. But try to debug it. Add a debugger statement and see why you get the error.