0.9.21 • Published 6 years ago

tcomb-form v0.9.21

Weekly downloads
3,247
License
MIT
Repository
github
Last release
6 years ago

build status dependency status npm downloads

"Simplicity is the ultimate sophistication" (Leonardo da Vinci)

Notice

tcomb-form is looking for maintainers. If you're interested in helping a great way to get started would just be to start weighing-in on GitHub issues, reviewing and testing some PRs.

Domain Driven Forms

The tcomb library provides a concise but expressive way to define domain models in JavaScript.

The tcomb-validation library builds on tcomb, providing validation functions for tcomb domain models.

This library builds on those two and realizes an old dream of mine.

Playground

This playground, while a bit outdated, gives you the general idea.

Benefits

With tcomb-form you simply call <Form type={Model} /> to generate a form based on that domain model. What does this get you?

  1. Write a lot less HTML
  2. Usability and accessibility for free (automatic labels, inline validation, etc)
  3. No need to update forms when domain model changes

Flexibility

  • tcomb-forms lets you override automatic features or add additional information to forms.
  • You often don't want to use your domain model directly for a form. You can easily create a form specific model with tcomb that captures the details of a particular feature, and then define a function that uses that model to process the main domain model.

Example

import t from 'tcomb-form'

const FormSchema = t.struct({
  name: t.String,         // a required string
  age: t.maybe(t.Number), // an optional number
  rememberMe: t.Boolean   // a boolean
})

const App = React.createClass({

  onSubmit(evt) {
    evt.preventDefault()
    const value = this.refs.form.getValue()
    if (value) {
      console.log(value)
    }
  },

  render() {
    return (
      <form onSubmit={this.onSubmit}>
        <t.form.Form ref="form" type={FormSchema} />
        <div className="form-group">
          <button type="submit" className="btn btn-primary">Save</button>
        </div>
      </form>
    )
  }

})

Output. Labels are automatically generated.

npm.io

Documentation

GUIDE.md

Browser compatibility: same as React >=0.13.0

Contributions

Thanks so much to Chris Pearce for pointing me in the right direction and for supporting me in the v0.4 rewrite.

Special thanks to William Lubelski (@uiwill), without him this library would be less magic.

Thanks to Esa-Matti Suuronen for the excellent humanize() function.

Thanks to Andrey Popp for writing react-forms, great inspiration for list management.

Contributing

CONTRIBUTING.md

0.9.21

6 years ago

0.9.20

6 years ago

0.9.19

6 years ago

0.9.18

6 years ago

0.9.17

7 years ago

0.9.16

7 years ago

0.9.15

7 years ago

0.9.14

7 years ago

0.9.13

7 years ago

0.9.12

7 years ago

0.9.11

7 years ago

0.9.10

8 years ago

0.9.9

8 years ago

0.9.8

8 years ago

0.9.7

8 years ago

0.9.6

8 years ago

0.9.5

8 years ago

0.9.4

8 years ago

0.9.3

8 years ago

0.9.2

8 years ago

0.9.1

8 years ago

0.9.0

8 years ago

0.8.2

8 years ago

0.8.1

8 years ago

0.8.0

8 years ago

0.7.10

8 years ago

0.7.9

8 years ago

0.7.8

8 years ago

0.7.7

8 years ago

0.7.6

8 years ago

0.6.10

8 years ago

0.7.5

8 years ago

0.6.9

8 years ago

0.7.4

8 years ago

0.6.8

8 years ago

0.7.3

9 years ago

0.6.7

9 years ago

0.7.2

9 years ago

0.6.6

9 years ago

0.6.5

9 years ago

0.7.1

9 years ago

0.7.0

9 years ago

0.6.4

9 years ago

0.6.3

9 years ago

0.6.2

9 years ago

0.6.1

9 years ago

0.5.6

9 years ago

0.6.0

9 years ago

0.5.5

9 years ago

0.5.4

9 years ago

0.5.3

9 years ago

0.5.2

9 years ago

0.5.1

9 years ago

0.5.0

9 years ago

0.4.11

9 years ago

0.4.10

9 years ago

0.4.9

9 years ago

0.4.8

9 years ago

0.4.7

9 years ago

0.4.6

9 years ago

0.4.5

9 years ago

0.4.4

9 years ago

0.4.3

9 years ago

0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.3.0-rc2

9 years ago

0.3.0-rc1

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.8

9 years ago

0.1.7

9 years ago

0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago