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

ns-schema-form

v0.1.1

Published

Web component made to display form and filters with json input.

Downloads

8

Readme

Form generator

It's a web component for creating forms from a JSON file based on the JSON schema. The output format is also a JSON file.

Getting Started

  • Install with npm i ns-schema-form

    and add it to your framework (StencilJs Doc)

    or set <script src="PATH/TO/YOUR/SCRIPT/ns-schema-form.js></script> into your index.html

  • Install reneco-fonts with bower bower install [email protected]:NaturalSolutions/RenecoFonts.git

  • Call <ns-schema-form></ns-schema-form> to use this component

  • Set your params

Configure params

JSON params must be like that:

{"form": {
	"items": [
		{ INSERT YOUR ITEMS HERE
        }],
        "i18next": { 
          	"lng": "fr",
          	"resources": {
            	"fr": {
              		"labels": {
                		INSERT YOUR LABELS TRANSLATION HERE
                	}
            	},
            	"validationErrors": {
	                INSERT YOUR VALIDATION ERRORS HERE
              	}
            }
        },
        "model": {
          ADD YOUR MODEL HERE
        },
        "validation": {
          ADD VALIDATION FIELDS HERE
        }
    },
    "framework": "INSERT FRAMEWORK POSSIBLE CHOICES",
    "config":{
    	INSERT CONFIGURATION HERE
    } 
}

You can choose ionic framework for display field: "framework": "ionic" write at the same level of "form". By default, there is no framework but you can choose class of each field (see Options list by type field below).

Some config options are available:

  • "domain": "http://YOUR_DOMAIN/" to choose the domain of your request (Ex: localhost)
  • "thesaurus-icon": "YOUR CLASS ICON" or "position-icon": "YOUR CLASS ICON" to change displayed icon.

Options list by type field

Each type must have 2 required arguments:

  • "key" : string (name of the field)
  • "type" : string (type of the field)

"classNames" field is not supported by Ionic There are different required and optional arguments according to type field:

Columns

| Required | Optional | |:-----------------------------------------:|:--------:| | "type": "cols" | "classNames": string (add class to field) | | "key": string ("name_of_cols") | | | | | | "cols" : table of objects | |

Text

| Required | Optional | |:---------------------------------:|:-----------------------------------------------:| | "type": "text" | "nolabel": boolean (true if no label displayed) | | "key": string ("name_of_field") | "placeholder": string | | | "disabled": boolean | | | "classNames": string (add class to field) |

Email

| Required | Optional | |:---------------------------------:|:-----------------------------------------------:| | "type": "email" | "nolabel": boolean (true if no label displayed) | | "key": string ("name_of_field") | "placeholder": string | | | "disabled": boolean | | | "classNames": string (add class to field) |

Number

| Required | Optional | |:---------------------------------:|:-----------------------------------------------:| | "type": "number" | "nolabel": boolean (true if no label displayed) | | "key": string ("name_of_field") | "placeholder": string | | | "max": integer (maximum value) | | | "min": integer (minimum value) | | | "classNames": string (add class to field) |

Date

| Required | Optional | |:---------------------------------:|:-----------------------------------------------:| | "type": "date" | "nolabel": boolean (true if no label displayed) | | "key": string ("name_of_field") | "placeholder": string | | | "display-format": string (Ex: "DD/MM/YYYY") | | | "classNames": string (add class to field) |

Textarea

| Required | Optional | |:---------------------------------:|:-----------------------------------------------:| | "type": "textarea" | "nolabel": boolean (true if no label displayed) | | "key": string ("name_of_field") | "placeholder": string | | | "autogrow": boolean -- for ionic framework | | | "cols": integer (number of columns) -- for ionic framework | | | "rows": integer (number of rows) -- for ionic framework | | | "classNames": string (add class to field) |

Checkbox

| Required | Optional | |:---------------------------------:|:-----------------------------------------------------:| | "type": "checkbox" | "nolabel": boolean (true if no label displayed) | | "key": string ("name_of_field") | | | | "color": string (primary,secondary,danger,light,dark -- for ionic framework) | | | "disabled": boolean | | | "indeterminate": boolean -- for ionic framework | | | "classNames": string (add class to field) |

Dropdown

| Required | Optional | |:---------------------------------:|:---------------------------------------------------------------------------------:| | "type": "dropdown" | "operators": table (list of select-options. Can be string, objects, integer, ...) | | "key": string ("name_of_field") | "nolabel": boolean (true if no label displayed) | | | "interface": string (action-sheet, alert, popover) | | | "multiple": boolean | | | "placeholder": string | | | "disabled": boolean | | | "classNames": string (add class to field) |

Thesaurus field

| Required | Optional | |:---------------------------------:|:------------------------------------------------:| | "type": "thesaurus" | "startNodeId" : integer (node to start the tree) | | "key": string ("name_of_field") | "lng" : string (choice are "en" or "fr") | | | "deprecated": boolean |

Position field

| Required | Optional | |:---------------------------------:|:------------------------------------------------:| | "type": "position" | "startNodeId" : integer (node to start the tree) | | "key": string ("name_of_field") | "lng" : string (choice are "en" or "fr") | | | "deprecated": boolean |

##Example

{"form": {
	"items": [{
		"key": "colonne generale",
		"type": "cols",
		"classNames": "d-flex",
		"cols": [{
			"key": "colonne de gauche",
			"classNames": "col-12",
			"type": "cols",
			"cols": [{
				"key": "dropdown",
				"type": "dropdown",
				"options": {
					"operators": ["a", "b", "c", "d", "e"]
				}
			},{
				"key": "email",
				"type": "email"
			},{
				"key": "checkbox",
				"type": "checkbox"
			},{
				"key": "thesaurus",
				"type": "thesaurus",
				"options": {
					"startNodeId": 167920
				}
			},{
				"key": "sous colonne de gauche",
				"type": "cols",
				"cols": [{
					"classNames": "col-7",
					"key": "id",
					"type": "dropdown",
					"options": {
						"operators": [{"value":"=", "label":"operators.="}, {"value":"<>", "label":"operators.<>"}]
					}
				},{
					"classNames": "col-5",
					"key": "id_text",
					"type": "text",
					"nolabel": true
				}]
			}]
		}]
		}, 
		{
			"key": "OK",
			"type": "submit"
		}
	]
},
	"i18next": {
		"lng": "fr",
		"resources": {
			"fr": {
				"labels": {
					"dropdown": "Menu déroulant",
					"translations_items": {
						"lang": "Langue",
						"title": "Title"
					}
				},
				"operators": {
					"=": "Eq",
					"<>": "Different"
				},
				"validationErrors": {
					"minLength": "Veuillez saisir au moins {{count}} caractères.",
					"maxLength": "Ne dois pas dépasser {{count}} caractères.",
					"email": "Veuillez saisir un email valide.",
					"required": "Ce champ est requis"
				}
			}
		}
	},
	"model": {
		"translations": [
			{
				"lang": "fr",
				"title": "bonjour"
			}, {
				"lang": "en",
				"title": "hello"
			}
		]
	},
	"validation": {
		"type": "object",
		"required": ["thesaurus"],
		"properties": {
			"thesaurus":{
				"type": "string",
				"thesaurusValidator": 167920
			},
			"email": {
				"type" : "string",
				"if": {
					"minLength": 1
				},
				"then": {
					"format": "email"
				},
				"else": {
					"minLength": 0
				}
			},
			"translations": {
				"type": "array",
				"items": {
					"type": "object",
					"properties": {
						"lang": {
							"type": "string",
							"minLength": 2,
							"maxLength": 2
						}
					}
				}
			}
		}
	},
	"config":{
		"domain": "localhost/"
	}
}

Filter component

The filter component will generate a filter form given an input config.

Component instanciation

The component is instanciated as follows

<ns-schema-filter
	domain = "the domain to use (for position and thesaurus)"
	config = "your config"
/>
<ns-schema-filter>

where config is a json of the form

{
	"fieldName" : {
		"type" : "<type>",
		"additionalProp" : "additional prop for the given type"
	},
	"anotherField" : {
		"type" : "<type>",
		"additionalProp" : "additional prop for the given type"
	},
	"..." : {}
}
  • fieldName : the name of your field

  • type : the type of the field. Available types are

    • number
    • string
    • date
    • dateInterval
    • booleanOptions (List of possible values for a field)
    • thesaurus
    • position
  • additionalProp : can be the following depending on the type

    • thesaurus :
      • startNodeID
      • deprecated
      • lng
      • position :
      • startNodeID
      • deprecated
        • lng

Example

<ns-schema-filter
	domain='http://localhost/' 
	config='{
		"stringField": {
			"type" : "string"
		},
		"numberField" : {
			"type" : "number"
		},
		"thesaurusField": {
			"type" : "thesaurus",
			"startNodeID": 167920,
			"lng" : "en"
		},
		"dateField" : {
			"type" : "date"
		},
		"dateIntervalField" : {
			"type" : "dateInterval"
		},
		"positionField" : {
			"type" : "position",
			"startNodeID" : 1,
			"lng" : "en"
		},
		"optionsField": {
			"type" : "booleanOptions",
			"options" : ["option1", "option2","option3", "option4","option5", "option6","option7", "option8"]
		}
	}'>
</ns-schema-filter>