1.4.4 • Published 5 years ago
trains-forms v1.4.4
TrainsForms
All in one React dynamic form builder, make form easier.
Install
npm install trains-forms --save;
// For theme: Semantic UI
npm install semantic-ui-css --save;
import 'semantic-ui-css/semantic.min.css';
// For theme: Bootstrap@4
npm install bootstrap --save;
import 'bootstrap/dist/css/bootstrap.min.css';
Features
- Render complex form by simple configs.
- Easily switch between view and edit mode.
- Built-in support for Semantic UI, Bootstrap.
- Built-in configurable validations.
- Built-in configurable error messages.
- Built-in date picker.
- Take advantage of standalone field components.
How to use
Simple Example
import useForm, { FORM_CONSTANTS };
const fields = [
{
name: 'form_message',
type: FORM_CONSTANTS.MESSAGE_TYPE,
title: 'A simple example of TrainsForm',
},
{
name: 'pet_name',
type: FORM_CONSTANTS.TEXT_TYPE,
title: 'Pet Name',
},
{
name: 'pet_type',
type: FORM_CONSTANTS.RADIO_TYPE,
title: 'Pet Type',
},
];
const values = { pet_name: 'Shilee' };
const options = {
pet_type: [
{ label: 'Dog', value: 1 },
{ label: 'Cat', value: 2 },
{ label: 'Bird', value: 3 },
{ label: 'Other', value: 4 },
],
};
const [formRender, {
getFormDetails,
resetFormValues,
validateFormValues,
}] = useForm({
fields, values, options, mode: FORM_CONSTANTS.EDIT_MODE,
});
return (
<div>
{formRender()}
<button
onClick={() => {
const details = getFormDetails();
console.log(details.isReady, details.values, details.errors);
}}
>
Get form status, values, errors.
</button>
<button onClick={resetFormValues}>
Reset to form initial values.
</button>
<button onClick={validateFormValues}>
Validate all fields and display error messages.
</button>
</div>
);
Configuration
Form Props
Form Configs
Field Props
1.4.4
5 years ago
1.4.3
5 years ago
1.4.2
5 years ago
1.4.1
5 years ago
1.4.0
5 years ago
1.3.3
5 years ago
1.3.2
5 years ago
1.3.1
5 years ago
1.3.0
5 years ago
1.2.3
5 years ago
1.2.2
5 years ago
1.2.1
5 years ago
1.2.0
5 years ago
1.1.3
5 years ago
1.1.2
5 years ago
1.1.1
5 years ago
1.1.0
5 years ago
1.0.0
5 years ago
0.0.3
5 years ago
0.0.2
5 years ago
0.0.1
6 years ago