npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ngx-show-form-errors

v1.0.2

Published

An Angular library providing a directive to automatically display form error messages.

Downloads

8

Readme

NgxShowFormErrors

This is an Angular library, consisting of a directive to automatically display form error messages.

The library can be installed in your Angular application with the following command:
npm install ngx-form-errors

To use the directive, you can apply it either to the form or directly to the input fields (it is not necessary to apply it to both). Example:

<form #form="ngForm" id="formId" ngxShowFormErrors>
    <input type="text" name="fieldName" #fieldName [(ngModel)]="fieldValue" required maxlength="10" />
    <div data-field="fieldName">
      <div data-validator="required">required field message</div>
      <div data-validator="maxlength">maxlength field message</div>
    </div>
</form>

Notice that below the field, you can declare a list of error messages. To do this, you must create a structure where there is a container with the data-field attribute, with the name of the field (in the case of Reactive Forms, use the value of formControlName), and inside it, a list of HTML elements with the validation text, where each validation is identified by the data-validator attribute, passing its type as the value.

Don't forget to import the directive in your module. Example:

import { ShowFormErrorsDirective } from 'ngx-show-form-errors';

imports: [
    ReactiveFormsModule,
    NgxShowFormErrorsDirective,
    ],

The directive is compatible with both Reactive Forms and Template Driven Forms.

The initial state will not display any error messages until a blur event occurs on the field or until the form is submitted. If the form is submitted, all errors will be displayed.

What the directive does to display the errors is add classes to the field and the error message elements. The library does not create any CSS styles, so you will need to create your own styles according to the classes the directive adds to the elements. The classes added by the directive are the ones natively used by Bootstrap 5, so if you use Bootstrap, you won’t need to worry about this.

The directive automatically adds the .invalid-feedback class to the container with the error messages, and .invalid-feedback-item to each message element. In addition, it will also add the .d-none class to each message element if the state is valid, and also add the .is-invalid class to the field if the state is invalid.

An example style for this would be:

.is-invalid {
    border: solid 1px red;
}
.invalid-feedback > .invalid-feedback-item {
    color: red;
}
.invalid-feedback > .invalid-feedback-item.d-none {
    display: none;
}