timdeschryver / ng-signal-forms

105 stars 7 forks source link

feat: add custom error directive and component. #2

Closed goetzrobin closed 1 year ago

goetzrobin commented 1 year ago

directive renders an error component and provides injector that allows access to the underlying form field. the injected form field can then be used to render the errors.

the error component is provided through an injection token and can therefore be configured as needed. if no component is provided we throw an error

just a prototype but maybe it's useful!

goetzrobin commented 1 year ago

@timdeschryver just updated my PR. I went ahead and implemented this structure:

{
 "required": {
    "details": true,
    "message": "Password is required"
  },
  "minLength": {
    "details": {
      "currentLength": 0,
      "minLength": 5
    },
    "message": "Password must be at least 5 characters long. Add at least 5 characters"
  },
}

I actually really like it! The current implementation also allows you to provide a default error message for your validator and override it on a field level!

I am blown away how powerful this is already!

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 1.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: