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

@it_resee/formvalidation

v1.2.1

Published

Documentation officiel : https://formvalidation.io

Readme

formvalidation

Documentation officiel : https://formvalidation.io

Installation

npm install @cafefrappe/formvalidation

Import

Dans le fichier TS :

import {formValidation, plugins} from '@cafefrappe/formvalidation';

Usage

private _initForm(): void {

    const form: HTMLFormElement = document.querySelector('#form');
    
    formValidation(form, {
        fields: {
            'login': {
                validators: {
                    notEmpty: {
                        message: 'Ce champ est requis.'
                    }
                }
            },
            'password': {
                validators: {
                    notEmpty: {
                        message: 'Ce champ est requis.'
                    }
                }
            }
        },
        plugins: {
            trigger: new plugins.Trigger(),
            submit: new plugins.SubmitButton(),
            defaultSubmit: new plugins.DefaultSubmit(),
            message: new plugins.Message({
                container: (field: string, element: HTMLElement): HTMLElement => {
    
                    return element.closest('.form-group') as HTMLElement;
                }
            })
        }
    })
    .on('core.validator.validating', (e: { element: HTMLElement }): void => {
    
        (e.element as HTMLElement).closest('.form-group').classList.remove('has_error');
    })
    .on('plugins.message.displayed', (e: { element: HTMLElement }): void => {
    
        (e.element as HTMLElement).closest('.form-group').classList.add('has_error');
    });
}

Les messages d'erreurs relatifs à un champ seront injectés à la fin du container parent ayant la classe "form-group" :

<div class="form-group">
    <input type="text" name="login">
    <!-- La DIV ci-dessous sera directement injecté par le FormValidation lors de l'initialisation du formulaire. -->
    <div class="fv-plugins-message-container">
        <!-- Pour chaque erreur de validation, une DIV sera injectée. -->
        <div data-field="login" data-validator="notEmpty">Ce champ est requis.</div>
    </div>
</div>

Utilisation des libraries externes

Par défaut la variable plugins n'intègre que les plugins natifs utilisés couramment pour le bon fonctionnement de la librairie.

FormValidation met à disposition une liste de plugin externes pouvant être intégrés au besoin : https://formvalidation.io/guide/plugins#external-plugins

Pour intégrer un plugin externe il suffit d'importer sa classe qui est accessible à la racine du package, et qui a pour identifiant le NOM_DU_PLUGIN concaténé avec Plugin :

Exemple avec le Plugin Recaptcha (https://formvalidation.io/guide/plugins/recaptcha) :

import {formValidation, RecaptchaPlugin} from '@cafefrappe/formvalidation';

const form: HTMLFormElement = document.querySelector('#form');

formValidation(form, {
    plugins: {
        recaptcha: new RecaptchaPlugin({
            element: 'captchaContainer',
            language: 'fr'
        })
    }

Compatibilité

Pour supporter les anciens navigateurs il est nécessaire d'importer le CDN 'es6-shim' directement dans le template HTML :

<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.3/es6-shim.min.js"></script>

Dans le but d'éviter toute erreur de typage liée à la librairie, il est nécessaire d'ajouter l'instruction suivante dans le fichier tslint.json :

{
    "linterOptions": {
        "exclude": [
            "node_modules/**"
        ]
    }
}