0.2.0 • Published 12 months ago

conventional-form v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Conventional form

Installation

yarn add conventional-form

Use name propertie of inputs

To have access to form values without input control you must use the name propertie of each input. If you have any value wich is not a real input value you must add an hidden input with the name you want.

Name convention

Your form value will be an object with keys as each input names in your form. You can define nested object and array with '-' in your name like this :

// List of your inputs names
'name.lastname';
'name.firstname';
'age';
'contacts.0.userId';
'contacts.0.text';
'contacts.1.userId';
'contacts.1.text';

// Your data will be like this

type Data = {
  name: { lastname: string; firstname: string };
  age: string;
  contacts: [{ userId: string; text: string }, { userId: string; text: string }];
};

Use form data or search params

import { getRequestSearchData, getRequestFormData } from 'conventional-form';

const data = getRequestSearchData(formData);
// or
const data = getRequestFormData(searchParams);
0.2.0

12 months ago

0.1.0

2 years ago