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

sad-lead-form-template

v1.2.2

Published

sad-lead-form-template

Downloads

11

Readme

SAD Lead Form Template

Usage

Installation

# Install
npm init
npm install sad-lead-form-template

# Go to dist/
cd node_modules/sad-lead-form-template/dist

# Open index.html
file:///path/to/project/node_modules/sad-lead-form-template/dist/index.html

Library content

dist/
├── index.html
├── css
│   ├── sad-lead-form.css
│   └── sad-lead-form-optional.css
└── js
    └── sad-lead-form-app.js

Integration

<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <title>Formulaire</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <!-- ––––––––––––––––––
     1 . CSS
    ––––––––––––––––––– -->
    <!-- [required] : This is a required stylesheet with no styling whatsoever.
         It's only here to make the application work
         hide/show elements, display error messages....
     -->
    <link rel="stylesheet" href="css/sad-lead-form.css">

    <!-- [optional] : This is an optional stylesheet for whoever wants a "plug and play"  type of form.
         It makes the form nicer to look at.
         Do not include it if you want to fully customize the application to your needs.
    -->
    <link rel="stylesheet" href="css/sad-lead-form-optional.css">

</head>
<body>

<!-- ––––––––––––––––––
 2 . HTML element
––––––––––––––––––– -->
<!-- HTML node in which to insert the form  -->
<div id="sad-lead-form"></div>

<!-- ––––––––––––––––––
 4 . JAVASCRIPT
––––––––––––––––––– -->
<!-- 
Library inclusion :
This adds a window (global) object : window.sad.leadFormModelInstance
-->
<script src="js/sad-lead-form-app.js"></script>

<script>
    // --------------------
    // 5 . Callback function
    // --------------------
    // Callback function that will be called once the form is valid and submitted
    const callBackFunction = () => {
        // We can access the generated model to be submitted (POSTed) to the API as :
        // A JSON object
        const formResultAsAJSONObject = window.sad.leadFormModelInstance.getFormAsJSON();
        console.log(formResultAsAJSONObject);
        // Or, a JS object
        const formResultAsAJSObject = window.sad.leadFormModelInstance.getFormAsObject();
        console.log(formResultAsAJSObject);

        const myHeaders = new Headers();
        myHeaders.append("Content-Type", "application/json");

        const requestOptions = {
            method: "POST",
            headers: myHeaders,
            body: formResultAsAJSONObject,
            redirect: "follow"
        };

        // POST the Lead to your backend project where you'll use your credentials to send it to our API.
        fetch("https://your-project-backend/uri", requestOptions)
            .then((response) => response.text())
            .then(() => {
                // Success : replace the form with a message
                document.getElementById('sad-lead-form').innerHTML = '<p>Le formulaire a bien été transmis.</p>';
            })
            .catch(error => {
                // Error : Print an error and re-enable form edition
                alert('Une erreur est survenue lors de la soumission du formulaire.');
                document.getElementById('sad-lead-form').style.pointerEvents = 'auto';
                console.log(error);
            });
    };

    // --------------------
    // 6 . Create the form / Configuration
    // --------------------
    new SadLeadFormApp.default({
        // [required] distributorCode : Code of the distributor
        distributorCode: "XXXXXXXXXXX",

        // [required] agencyCode : Code of the agency
        agencyCode: 'XXXXXXXXXXX',

        // providerConfig : List of providers
        providerConfig: {
            type: 'agency',
            selections: [{code: 'code1', name: 'Name1'}, {code: 'code2', name: 'Name2'}]
        }

        // [required] htmlSelector : HTML selector in which to inject the <form>
        // In this example : <div id="sad-lead-form"></div>
        htmlSelector: "#sad-lead-form",

        // [required] rgpdDescription : This is the RGPD distributor description.
        rgpdDescription: "Lorem ipsum dolor sit amet..",

        // [required] callback : This is the callback function in which we can do whatever we want with the generated model (typically POST it to the API)
        callback: callBackFunction
    });
</script>
</body>
</html>

Development (Senioradom)

Build

rm -rf dist;
mkdir ./dist/
parcel build src/js/sad-lead-form-app.js --public-url ./ --out-dir ./dist/js  --no-minify --global SadLeadFormApp
parcel build src/css/sad-lead-form.scss --public-url ./ --out-dir ./dist/css
parcel build src/css/sad-lead-form-optional.scss --public-url ./ --out-dir ./dist/css
cp to-dist/index.html ./dist/

Dist

Increment package.json version.

# If not logged
npm login

npm publish