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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-easy-validation

v1.0.9

Published

Automatically add Tippy.js tooltips to invalid input fields, using Angular's template-driven form validation.

Downloads

5

Readme

NgEasyValidation

Automatically add Tippy.js tooltips to input fields containing its errors.

It uses the validation logic from Angular's template-driven forms, and wraps it in a directive that adds tooltips to the respective input fields.

Demo

Check out the demo

Installation

Install it via NPM

npm i ng-easy-validation

Include the module

import { NgEasyValidationModule } from 'ng-easy-validation';

Basic usage

1. Prepare form

To begin, add a reference to FormGroup on the form. <form #form="ngForm">

Then add the ngEasyValidation directive, together with the requirements (more on this later).

<form #form="ngForm" [ngEasyValidation]="requirements">

2. Prepare input fields

Since this library wraps Angular's template-driven form, every input field needs to have an [(ngModel)] assigned to it, as well as a unique name.

<input type="text" [(ngModel)]="firstname" name="firstname">

3. Create a requirements object

The requirements must be an object with keys that refer to the name property, and values that contain a list the validators for that field.

requirements: any = {
        "firstname": [
            { validator: required() },
            { validator: maxLength(50) },
            { validator: invalidValues(["Brad", "Chad", "Bob"]) }
        ]
    }

Properties of validation object

validator

This is the object that will be executed to help determine if a field is valid or not. This library supports all of Angular's built-in validators, plus many custom ones you can use in your application.

message (optional)

The error message that will be shown in the tooltip. When left empty, an appropriate message will be generated.

tooltipsOnInit (optional)

A boolean that tells to library to show tooltips immediately after the form has been loaded into the page. Default value is false.

Directive options

The ngEasyValidation directive supports modification through these options.

tippyProps

An object with the default properties for the Tippy.js tooltips. See all properties.

validationDebounceTime

A number reprenting the amount of milliseconds that will be applied to RxJS' debounceTime operator before applying the tooltips.

This can be used to increase the performance of heavy forms with many input fields.

Validators

Importing

ngEasyValidation supports lots of validators that can be imported as such

import { required, maxLength, invalidValues } from 'ng-easy-validation';

List of validators

validator | Invalid when|Notes ------------- |-------------|------------- required() | value is null or empty requiredTrue() | value is not true|mostly used with checkboxes nullValidator() | never|performs no operation minLength(minLength: number) | value has less characters than minLength maxLength(maxLength: number) | value has more characters than maxLength email() | value is not a valid email address min(min: number) | value is less than min max(max: number) | value is more than max between(min: number, max: number) | value is less than min or more than max invalidValues(invalidValues: any[] \| any, valueModifier: (any) => any = x => x) | value is in invalidValues|valueModifier can be used to modify what was entered before it will be matched. Ex: apply toLowerCase() before matching requiredValues(requiredValues: any[] \| any, valueModifier: (any) => any = x => x) | value is not in requiredValues|valueModifier can be used to modify what was entered before it will be matched. Ex: apply toLowerCase() before matching invalidCharacters(invalidCharacters: string) | value contains any of the characters in invalidCharacters|invalidCharacters is a string containing all the characters conditionalValidator(validator: ValidatorIdMap, condition: (AbstractControl) => boolean) | condition is met and validator is invalid sqlObjectName() | value is not a valid SQL object name isInteger() | value is not an integer isNumeric() | value is not a numeric isAlphaNumeric() | value is not alphanumerical isAlphabetical() | value is not alphabetical startsWith(str: string) | value doesn't start with str endsWith(str: string) | value doesn't end with str

License

MIT