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

dynamic-popup-form

v1.0.0

Published

popup dialog with dynamic form

Downloads

4

Readme

Dynamic-popup-form

This is module to create dynamic dialog form which asking user for data. Now allowed text input, file input, textarea, select and label text. It is completely independent and don't require depencencies neither on frameworks nor libraryes.

Using in browser

To use in browser just add dynamic-popup-form.js with <script> tag and dynamic-popup-form.css in <style> tag.

Using with bundlers (Webpack, Rollup etc)

I didn't try yet, but i suppose this can work.

Styles

All styles containing in file dynamic-popup-form.css. This is for convient to customize. You can edit this styles, bundle it etc.

Documentation

Dynamic Popup Form Dialog is created be class PopupForm with particular parameters. These parameters is a object, containing description needed to create dialog. Method 'show' show the created dialog. Dialog window have two buttons 'Ok' and 'Cancel'. Object parameters have to provide two methods to deal with user choise. One method is invoked when user clicks 'Ok' and second method is invoked when user clicks 'cancel'.

	var params = 
	{
		'type': 'label', 
		value: 'You really want to destroy this?', 
		handler: function (value) 
		{
			Destroy();
		}
	};


	var form = new PopupForm(params);
	form.show();

Input types

Object params have to contain some keys.

  • type - type of html input DOM element. Now following types is accepted:
  • label - will be created <label> html element. This is convieced for confirmation dialogs.
  • text - will be created <input type='text'> element.
  • file - will be created <input type="file"> element.

Select

select - will be created <select> element.

Initial values must be in 'value' key:

Creating dialog containing text label and two buttons 'Ok' and 'Cance'.

var params
{
    'type': 'label',
    'value': 'Some text?'
}

Creating dialog with text input field

var params
{
    'type': 'text',
    'value': 'Some text'
}

Creating dialog with text textarea

var params
{
    'type': 'textarea',
    'value': 'Some text'
}

When 'type' is 'select' you have to provide set of option in 'options' key. This key can be either array or object. Keys of object set attribute 'value' of 'option' html element. Values set text in option html element. Key 'value' can contain initial selected element.

This parameters

var params 
{
    'type': 'select',
    'options': {
        'option value 1': 'option name 1',
        'option value 2': 'option name 2'
    },
    value: 'option name 1',
}

result in:

<select>
<option value="option value 1" selected>option name 1</option>
<option value="option value 2">option name 2</option>
</select>

Or can use array. Then option value and option text will be same.

var params 
{
    'type': 'select',
    'options': [
        'option 1', 'option 2'
    ],
    value: 'option 1'
}

<select>
<option value="option 1" selected>option 1</option>
<option value="option 2">option 2</option>
</select>

List of fields

There is can use list of fields if one fields is not enough. Descriptions of fields are set in key 'fields'. It is array of object like this:

var params {
    fields : [
        {
        type: select,
        options : 
            {
                "one": "1",
                "two": "2"
            }
        value: "1"
        "data-value": "tag"
        },
        {
            type: text,
            "data-value": "comment"
        }
    ],
    handler : function (value) {
        console.log(JSON.stringify(value));
    }
}

This print some like

{ 
    "tag": "1",
    "comment": "some text"
}

Each object in 'fields' array contain keys - type, value, options, etc, which is need to field of this type. Argument 'value' passed in 'handler' contain object, where keys are 'data-value' value.