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

react-data-form

v1.0.0

Published

Easy input form component that handles data binding

Downloads

1

Readme

react-input-schema

This is one of many components that tries to solve the form input problems of React. As I tried many diffent solutions I found that all of them try to enforce a certain layout. I want a solution that just provides an easy way to fix the binding of data to input components without any interferance in the way I do my layout.

Simple

This component provides a simple way of displaying an input form and automatic binding of data. All you have to do is to provide the data, one or more schema's.

Formatting

An optional feature is the formatting of data. Per field you can configure if you want to format the data value into an input value and if you want to format the entered value into a data value.

For example: Suppose your data structure contains a date field. You do want to format this value into a locale date format and format the entered value back into a date value.

Validation

An other optional feature is date validation. You can provide a function that validates a value. This is a per field configuration.

Field style

If a field fails, the css class of the field can be changed based on the validation.

Schema style

If a schema fails, the css class of the schema can be changed based on the validation.

Form style

If a form fails, the css class of the schema can be changed based on the validation.

If one validation fails, the form cannot submit.

Submit

When the form submits, you receive bunch of information:

  • The values (of course)
  • The original values
  • Per field a boolean that tells if the value changed
  • The entered values
  • The formatted values

example1: A simple schema

const schema = [
  { id: 'firstname', component: (props) => <Row><Col>Firstname:</Col><Col><input {...props} /></Col><Row>}
  { id: 'lastname', component: (props) => <Row><Col>Lastname:</Col><Col><input {...props} /></Col><Row>}
];

return (
  <Form data={myData}>
    <Schema schema={schema} />
  </Form>
)

example 2: Two schema's

const schema1 = [
  { id: 'firstname', component: (props) => <Row><Col>Firstname:</Col><Col><input {...props} /></Col><Row>}
  { id: 'lastname', component: (props) => <Row><Col>Lastname:</Col><Col><input {...props} /></Col><Row>}
];
const schema2 = [
  { id: 'birthdate', component: (props) => <Row><Col>Date of birth:</Col><Col><input {...props} /></Col><Row>}
  { id: 'birthplace', component: (props) => <Row><Col>Place of birth:</Col><Col><input {...props} /></Col><Row>}
];

return (
  <Form data={myData}>
    <Column>
      <Schema schema={schema1} />
    </Column>
    <Column>
      <Schema schema={schema2} />
    </Column>
  </Form>
)

example 3: Validation


const ageValidation = age => (age >= 18 && age < 65);

const schema = [
  { id: 'firstname', component: (props) => <Row><Col>Firstname:</Col><Col><input {...props} /></Col><Row>},
  { id: 'lastname', component: (props) => <Row><Col>Lastname:</Col><Col><input {...props} /></Col><Row>},
  { id: 'age', validate: ageValidation, component: (props) => <Row><Col>Age:</Col><Col><input {...props} /></Col><Row>}
];

return (
  <Form data={myData}>
    <Schema schema={schema} />
  </Form>
)