0.6.2 • Published 6 years ago

prg-form v0.6.2

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

Prg Form

React Form components for Bulma.css.

There is API Documentation.

Usage within Form

import { Form, Input } from 'prg-form';

<Form
    className="special-class"
    onSubmit={(values, form) => console.log(values)}
    onChange={(input) => console.log(input.name, input.getValue())}
    values={values}
>
    <Input type="email" name="inputName" label="Input Label" />
    <button>Submit</button>
</Form>

Usage without Form

  • onchange event is not passed to form
import { Input } from 'prg-form';

<Input
    name="inputName"
    label="Input Label"
    value={value}
    onChange={(value, input) => {}}
/>

Basic Form Components

  • import { Input } from 'prg-form';
    
    <Input
        name="inputName"
        label="Input Label"
        type="password"
        maxLength={24}
    />
  • import { Checkbox } from 'prg-form';
    
    <Checkbox
        name="checkbox"
        defaultValue
    />
  • import { TextArea } from 'prg-form';
    
    <TextArea
        name="inputName"
        readOnly
        cols={30}
        rows={7}
    />
  • Is nice, because it works with native <File> objects.

    import { File } from 'prg-form';
    
    // as array of files
    <File
        name="files[]"
        multiple
    />
    
    <File
        name="file"
    />

Advanced using the file upload

import { File, ValidatorForm, flat } from 'prg-form';
import Validator from 'prg-validator';

export default function Component ({ onSendSuccess, onSendError }) {
    const validator = new Validator();

    validator.add('file')
        .isFileMaxLength('shlould be smaller then 1Mb', '1m')
        .isFileMime('Should be an excel file', [
            'application/vnd.ms-excel',
            'application/msexcel',
            'application/x-msexcel',
            'application/x-ms-excel',
            'application/x-excel',
            'application/x-dos_ms_excel',
            'application/xls',
            'application/x-xls',
            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        ])
        .toFileData();

    const onSubmit = (formData) => {
        const data = new FormData();

        const flatData = flat(formData);

        Object.keys(flatData)
            .forEach((key) => {
                data.append(key, flatData[key]);
            });

        this.request = $.ajax({
            method: 'POST',
            url: '/api/upload',
            dataType: 'json',   // JSON Response
            processData: false, // Don't process the files
            contentType: false, // Automatic content type
            data,
            success: responseData => onSendSuccess(responseData),
            error: jqXHR => onSendError(jqXHR)
        });
    };

    return (<div className="container">
        <ValidatorForm
            validator={validator}
            onSubmit={data => onSubmit(data)}
        >
            <File
                name="file"
                label="Please put the Excel file here"
            />
            <button className="button">Go</button>
        </ValidatorForm>
    </div>);
}
0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.7

6 years ago

0.5.6

6 years ago

0.5.5

6 years ago

0.5.4

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.2-alpha.5

6 years ago

0.5.2-alpha.4

6 years ago

0.5.2-alpha.3

6 years ago

0.5.2-alpha.2

6 years ago

0.5.2-alpha.1

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.5.0-alpha.2

6 years ago

0.5.0-alpha.1

6 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago