goetzrobin / spartan

Cutting-edge tools powering Angular full-stack development.
https://spartan.ng
MIT License
1.09k stars 120 forks source link

feature(form-field) create new component to handle errors and hints #320

Open cjosue15 opened 6 days ago

cjosue15 commented 6 days ago

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

Which package are you modifying?

What is the current behavior?

None

Closes #294

What is the new behavior?

Create a new component to handle errors and hints like the material functionality but with the shadcn styles.

Does this PR introduce a breaking change?

Other information

cjosue15 commented 1 day ago

I added some comments! I really like the idea of this and the overall approach seems fine to me, too. One big question I have: Is there a way to support this with uncontrolled form controls, too? e.g. just add a (host) directive to any form control that's Angular form compatible and automatically get the functionality, instead of having to manually update the form state on every doCheck

Thanks for review it, when you say uncontrolled form controls, you mean inputs or selects without any of these (FormControl or formcontrolName). Also I think it is not possible to use this validation as HostDirective because only some components must have the errorState, another point is each component that will be used inside the FormFIeld component should be use the BrnFormFieldControl in the providers, to be identified by the parent(form-field), additionally using the update of the error in the ngDoCheck is the only way, at least that I know of, where I can reevaluate on every change detection when the error is triggered.