formulaire

0.0.8 • Public • Published

README

Developing

Install

#!bash

npm install formulaire

(formulaire uses lodash)

Using formulaire

#!javascript

var formulaire = require('formulaire');

var myForm = formulaire({
    //options
});

Returns cool html code ready to use

API Options

No default values (pending to do)

Option Value
formClass STRING
formId STRING
action STRING
method POST | GET
fieldClassWrapper STRING Equivalent class to wrapper of the field
fieldClass STRING Class definition to inputs
submit.type link | button | input
submit.clase STRING
submit.href STRING
submit.onclick STRING
submit.field STRING
field.type text | password | color | date | datetime-local | email | month | number | range | search | tel | time | url | week | radio | checkbox | select | textarea

Code Example

#!javascript

var formulario = formulaire({
        formClass : 'form',
        formId : 'formulario_ID',
        action: '/send',
        method: 'post',
        fieldClassWrapper: 'form-group',
        fieldClass: 'form-control',
        submit: { 
            type: 'link',
            clase: 'btn btn-primary sender',
            href: 'javascript:void(0)',
            onclick: null,
            value: 'Enviar'
        },
        fields: {
            name: { type: 'text', required: true },
            surname: { type: 'text', required: true},
            email: { type: 'email', required: true},
            age: { type: 'number'},
            country: {
                type: 'select',
                default: 'Select your country',
                required: true,
                options: {
                    spain: { label: 'Spain', selected: true},
                    usa: { label: 'USA'}
                }
            },
            sex: {
                type: 'radio',
                options: {
                    m: { label: 'Male'},
                    f: { label: 'Female'}
                }
            },
            preferences: {
                type: 'checkbox',
                options: {
                    soccer: { label: 'Soccer', checked: true },
                    basket: { label: 'Basket'},
                    tennis: { label: 'Tennis'},
                    volley: { label: 'Volley'},
                    hockey: { label: 'Hockey'},
                }
            },
            observations: { type: 'textarea', required: true }
        }
    });

Now, you can use an JSON file to define the form

#!javascript
var defForm = require('./json/form_example.json');
var formulario = formulaire(defForm);

Dependents (0)

Package Sidebar

Install

npm i formulaire

Weekly Downloads

2

Version

0.0.8

License

MIT

Last publish

Collaborators

  • edualfaro