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

universal-quick-forms

v1.2.1

Published

With **QuickForms** you can: - Create fast and easily configurable Forms which uses only your **form model**, **QuickForm** to specify what this field do and **UniversalForm** as a wrapper - Create your own components, which allow you to manage your dat

Downloads

8

Readme

QuickForms

With QuickForms you can:

  • Create fast and easily configurable Forms which uses only your form model, QuickForm to specify what this field do and UniversalForm as a wrapper
  • Create your own components, which allow you to manage your data with complex structure

GitHub Page NpmJS Page

Table of Content

Installation

In terminal you write:

npm install universal-quick-forms

Package uses and is designed for ReactJS, so obviously, it's required to have it :)

How to use

Create form model

const registerUserModel = {
  userName: ''
  password: ''
  repeatPassword: ''
};

Create QuickForm object. Note: every field of the QuickForm object must match the name of FormModel

const registerUserQuickForm = {
  userName: {
	  type: 'text',
	  placeholder: 'User Name'
  },
  password: {
  	  type: 'password',
	  placeholder: 'Password'
  },
  repeatPassword: {
  	  type: 'password',
	  placeholder: 'Repeat Password'
  }
};

QuickForms object

UniversalForm

formObject

setFormObject

onSubmitAsync

quickForms

The object which consists of QuickForms fields. Must contain fields which names are exactly like formObject's field names. Values of the fields must be QuickForm object

Example:

const userQF = {
    userName: {
		type: 'text'
	},
	password: {
		type: 'password',
		
	}
}; 

return (<UniversalForm
	formObject={userObj}
	quickForms={userQF}
	setFormObject={setUserObj}>
		<button type="submit">Press me</button>
</UniversalForm>);

allDisabled

Boolean value. If it's true, then all of the components are set to disabled By default false

needsValidation

Boolean value. Set to true, if you need to have a validation of the form; By default false

Example:

const  clientValidationFunc = (formObj) => {};  
const  serverValidationFunc = (serverErrors, formObj) => {};
// See below for implementation of these functions 

return (<UniversalForm
	formObject={userObj}
	quickForms={userQF}
	setFormObject={setUserObj}
	needsValidation={true} // If false, ignore validation checks
	clientValidationFunc={clientValidationFunc}
	serverValidationFunc={serverValidationFunc}>
		<button type="submit">Press me</button>
</UniversalForm>);

Validation

You can have custom validations of any of your components before and after making a server request.

A user would see a validation errors (if present) only after he/she tries to make the first submit. After the first submit, on every change of the value clientValidationFunc is triggered.

If clientValidationFunc check was OK, then the submit to the server is performed. If server responded with "HTTP 400 Bad Request", serverValidationFunc is triggered.

clientValidationFunc

A function which works every time a user change any value of the components.

The function receives formObj with the current state of the object.

Must return object errors, where field names are exactly like the formObject's field names. Value of those fields must be string. This string value is displayed as the errors of components

Example:

const  clientValidationFunc = (testingObj) => {
	const  errors = {};
	if (!testingObj.userName) {
		errors.userName = "UserName is required";
	} else  if (testingObj.userName.length < 3) {
		errors.userName = "Must be at least 3 characters";
	}

	return  errors; // Must return {key: 'value'} object 
		where 'key'-s are the same as formObj's field names 
};

return (<UniversalForm
	formObject={userObj}
	quickForms={userQF}
	setFormObject={setUserObj}
	needsValidation={true} // If false, ignore validation checks
	clientValidationFunc={clientValidationFunc}>
		<button type="submit">Press me</button>
</UniversalForm>);

serverValidationFunc

In case if Server responded with "HTTP 400 Bad Request" and the response contains server model errors, you can display the server message to the user by using serverValidationFunc function.

The function receives serverErrors as the response from the server, and formObj with the current state of the object.

Must return object errors, where field names are exactly like the formObject's field names. Value of those fields must be string. This string value is displayed as the errors of components

Example:

const  serverValidationFunc = (serverErrors, formObj) => {
	const serErr = serverErrors.response.data.errors; // Axios response object
    const errors = {};
	Object.keys(serErr).map(err  =>  errors[err] = serErr[err][0]);

	return  errors;
};

return (<UniversalForm
	formObject={userObj}
	quickForms={userQF}
	setFormObject={setUserObj}
	needsValidation={true} // If false, ignore validation checks
	serverValidationFunc={serverValidationFunc}>
		<button type="submit">Press me</button>
</UniversalForm>);

In this case we just need to map server response to the default errors object. In the example above axios' post method is used.