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

orange-forms-js

v3.0.2

Published

Make form validation easy.

Downloads

7

Readme

Orange Forms JS

Make form validation easy.

Requirements

This package is thinking to use with webpack.

Dependencies

custom-filters-js
lit-element

Check package.json for more information.

Installation

npm i orange-forms-js

Usage

In your main .js add orange-forms.js

import 'orange-forms';

And in your form add the class orange-form

<form name="my_form" class="orange-form">...</form>

Your form needs a name.

The orange-forms automatically add to your form a class called OrangeForm, check the documentation below. If you require the class associated with the form you can get it using globalThis['orangeForms'], for example:

console.log(globalThis['orangeForms']['my_form']);

The orange-forms.js file will also automatically import the files:

./css/styles.css

Loads the styles that Orange form needs.

./components/ff-notices-cpt.js

Loads a component related to notifications from a field or a form. Check the documentation for components here

./components/field-cpt.js

Loads a component that add a label, an input and the component ff-notices-cpt. Check the documentation for components here

./orange-form

Loads the class that validate and process the data of inputs.

Class OrangeForm

This class validates the fields that contain the field attribute of a form, obtains their values and sends them as a JSON to the url specified in the action attribute of the form. The JSON is sent via fetch.

A JSON response is expected from the url of the action attribute of the form.

Properties

fields

Returns the fields that contain the field attribute in the form.

data

Returns the values of the fields as a JSON.

redirectSuccess

Returns the url where the site should go if the JSON response success is true.

redirectError

Returns the url where the site should go if the JSON response success is false.

reset

Get or set if the form will to reset when submit is complete and if the JSON response success is true.

Filters

You can use filters in Orange Forms.

To add a filter you can use:

globalThis['orangeForms']['my_form'].addFilterListener('filter_name', function(p1, p2, ...){
	console.log(p1, p2, ...);
	return p1;
});

The available filters are:

fields

globalThis['orangeForms']['my_form'].addFilterListener('fields', function (fields) {
	console.log(fields);
	return fields;
});

isValid

globalThis['orangeForms']['my_form'].addFilterListener('isValid', function (isValid, fields) {
	console.log(isvalid, fields);
	return isvalid;
});

data

globalThis['orangeForms']['my_form'].addFilterListener('data', function (data, fields) {
	console.log(data, fields);
	return data;
});

sendOpts

You can change the fetch header options. Find "fetch header javascript" in your favorite search engine if you want more documentation.

globalThis['orangeForms']['my_form'].addFilterListener('sendOpts', function (fetchHeader, data) {
	console.log(fetchHeader, data);
	return fetchHeader;
});

Methods

constructor

Require a html form.

isValid

Returns true or false if the fields have a valid value.

fieldsNoticesReset

Reset field notifications.

send

Send the values of the fields in JSON to the url of the name attribute of the form. It expects a JSON response with the following structure:

{
	"success": false,
	"notice": "There was an error, check fields.",
	"fields": {
		"field_email": [
			"Your email is not correct",
			"Your email does not a correct format."
		],
		"field_date": "The date is not correct."
	}
}

Where:

  • success returns if the query was correct true or false if an error occurred.

  • notice returns a message related to the query response.

  • fields returns an individual message or messages related to the field.

Events

Any event available in the html forms is available in Orange Form.

globalThis['orangeForms']['my_form'].addEventListener('event_name', function (e) {});

Additionally, the following events can be used:

beforeValid

This event is called before checking if the fields are valid.

beforeSend

This event is called before sending the JSON with the values of the fields.

afterSend(e)

This event is called after receiving the response from the server.

In e.detail you can get the data returned by the server, check method send to know the structure of the JSON that is expected to be received.

Notices

The file form-notices.js has the messages used in the form, as 'Please, check notices in fields.', if you want to translate or change these texts you can use a script tag:

<script id="orange-forms-form-notices" type="application/json">
	{ "checkFields": "Please, check fields." }
</script>

Individually, the texts can be changed directly in the form using the notices attribute, for example:

<form
	name="my_form"
	notices='{ "checkFields": "Please, check fields." }'
></form>

Or you can change directly using javascript:

globalThis['orangeForms'][iterator.name].notices.checkFields =
	'Please, check fields.';

Components

You can check components documentation here.