Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Ninja-Squad/ngx-valdemort

Simpler, cleaner Angular validation error messages
https://github.com/Ninja-Squad/ngx-valdemort

Last synced: 23 days ago
JSON representation

Simpler, cleaner Angular validation error messages

Awesome Lists containing this project

README

        

[![CircleCI](https://circleci.com/gh/Ninja-Squad/ngx-valdemort.svg?style=svg)](https://circleci.com/gh/Ninja-Squad/ngx-valdemort)
[![Codecov](https://codecov.io/gh/Ninja-Squad/ngx-valdemort/branch/master/graph/badge.svg)](https://codecov.io/gh/Ninja-Squad/ngx-valdemort)

# ngx-valdemort

ngx-valdemort gives you simpler, cleaner validation error messages for your Angular components.

## Why should you care?

If you've ever written forms like the following:

```html


@if (form.controls.email.invalid && (f.submitted || form.controls.email.touched)) {


@if (form.controls.email.hasError('required')) {
The email is required

}
@if (form.controls.email.hasError('email')) {
The email must be a valid email address

}

}


@if (form.controls.age.invalid && (f.submitted || form.controls.age.touched)) {


@if (form.controls.age.hasError('required')) {
The age is required

}
@if (form.controls.age.hasError('min')) {
You must be at least {{ form.controls.age.getError('min').min }} years old

}

}

Submit

```

ngx-valdemort allows writing the above form in a simpler, cleaner way by using the `ValidationErrorsComponent`:

```html



The email is required
The email must be a valid email address



The age is required
You must be at least {{ error.min }} years old

Submit

```

Even better, you can define default error messages once, and use them everywhere, while still being able to
override them when needed:

```html




You must be at least {{ error.min }} years old

Submit

```

It works with `ngModel` too!

```html

```

Learn more and see it in action on [our web page](https://ngx-valdemort.ninja-squad.com/)

## Installation

Using the CLI: `ng add ngx-valdemort`

Using npm: `npm install ngx-valdemort`

Using yarn: `yarn add ngx-valdemort`

## Getting started

- Import `ValdemortModule`, and other needed classes from ngx-valdemort
- Add the module to the imports of your application module
- Use `` in your forms
- Enjoy!

Go further:

- define default error messages using ``
- configure the look and feel globally by injecting and customizing the `ValdemortConfig` service

## Issues, questions

Please, provide feedback by filing issues, or by submitting pull requests, to the [Github Project](https://github.com/Ninja-Squad/ngx-valdemort).