npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

js-form-builder

v1.9.0

Published

React component to generate a form from javascript object.

Downloads

55

Readme

Component form builder

Build Status npm version GitHub issues Downloads

Requirements

  • Node version >= 6.2

See a demo

https://df4iw.csb.app/

See how works

https://codesandbox.io/s/js-form-builder-df4iw?file=/src/index.js

Props

| Prop name | Required | Default value | Prop value type | Description | |:--------------------:|:--------:|:--------------:|:----------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------:| | fields (See doc) | - | [] | Array | List of all fields for the form | | form | - | {} | Object | Form configuration to submit fields (Action, Method, enctype) | | container | - | null | Jsx | Wrapper container for all form | | fieldGroupContainer | - | null | Jsx | Wrapper to group of fields Each block of field will renderen into this container | | fieldContainer | - | null | Jsx | Wrapper for each field. | | formErrorContainer | - | null | Jsx | Wrapper for form error message | | hasToSubmit | - | true | Boolean | If submit button should submit form. If this prop is false on submit button just will return a json with all fields values. (Only if all fields are valid) | | showSubmitButton | - | true | Boolean | If form has to render a button to submit. | | showFormErrorMessage | - | true | Boolean | If form has to render a error message on click submit. | | showFieldsErrorsOnFailSubmit | - | true | Boolean | If form has to show each field with error on fail submit. | | onSuccess | - | Empty function | Function | Called on click submit and all fields are valid | | onError | - | Empty function | Function | Called on submit form with errors. Returns object with field name and error message | | | | | | | | | | | | |

Usage

import React from 'react';
import ReactDOM from 'react-dom';

import FormBuilder from 'js-form-builder';


const displayOnChangeFieldValue = (event) => {
    console.log(event.target.value);
};

const form = {
    action: '.',
    method: 'POST',
};

const fields = [
    {
        id: 'name',
        name: 'name',
        type: 'text',
        className: 'class_name',
        required: true,
        onChange: displayOnChangeFieldValue,
    }, {
        id: 'lastName',
        name: 'lastName',
        type: 'text',
        className: 'class_name',
        required: true,
        onChange: displayOnChangeFieldValue,
    },
];
/**
* Render form into a custom html block.
*/
const Container = ({ children, onSubmit }) => (
    <div className="container-form">
        {children}

        <button onClick={onSubmit}>Custom submit form</button>
    </div>
);

/**
* Render fields group into a custom html block.
*/
const fieldGroupContainer = ({ children, label }) => (
    <div className="form-group">
        {label}
        {children}
    </div>
);

/**
* Render field into a custom html block.
*/
const fieldContainer = ({ children, label }) => (
    <div className="form-control">
        {label}
        {children}
    </div>
);


/**
* Render label field into a custom html block.
*/
const labelContainer = ({ children }) => (
    <label className="label">
        {children}
    </label>
);

/**
* Render fields error message into a custom html block.
*/
const formErrorContainer = ({ children }) => (
    <div className="error">
        {children}
    </div>
);

/**
* Called on submit button.
* Return all fields data as json
*/
function onCustomSubmit(formData) {
    console.log(formData);
}


ReactDOM.render(
 <FormBuilder
        form={form}
        fields={fields}
        container={Container}
        fieldContainer={fieldContainer}
        fieldGroupContainer={fieldGroupContainer}
        labelContainer={labelContainer}
        formErrorContainer={formErrorContainer}
        onSubmit={onCustomSubmit}
        hasToSubmit={true}
        showSubmitButton={false}
        hasToShowLabel={true}
        showFormErrorMessage={true}
        showFieldsErrorsOnFailSubmit={true}
    />,
    document.getElementById('form'),
);

How to collaborate

  • Clone the project git clone https://github.com/jojo5716/form-builder-js
cd form-builder-js/
  • Install dependencies
npm ci
  • Start the development. This will command will start the development server builds, automatic testing and linting.
npm start
  • Open http://localhost:8080/ in a browser.