npm.io
0.4.1 • Published 8 years ago

react-bforms

Licence
MIT
Version
0.4.1
Deps
1
Size
254 kB
Vulns
0
Weekly
0

React Bootstrap Forms

Demo

Quick example

import BForms from 'react-bforms';
var {Form, Input} = BForms;


export class LoginForm extends React.Component {

    render() {
        return (
            <Form ref='form' onSubmit={this._onSubmit.bind(this)}>
                <Input name='username'
                       label='Email'
                       type='email'
                       validators={[username()]}/>

                <Input name='password'
                       label='Password'
                       type='password'
                       validators={[password()]}/>

                <div>
                    <button className='btn btn-primary'>Login</button>
                </div>
            </Form>
        );
    }

    _onSubmit() {
        var values = this.refs.form.getValues();
        console.log(values);
    }
};


var username = function(message) {
    message = message || 'Example: username@example.com';

    return function(value) {
        if (value.indexOf('@') === -1) {
            return message;
        }

        return '';
    };
};


var password = function(message) {
    message = message || 'Please enter password';

    return function(value) {
        if (!value) {
            return message;
        }

        return '';
    };
};

Keywords