{"id":13394452,"url":"https://github.com/insin/newforms","last_synced_at":"2025-04-12T23:42:45.897Z","repository":{"id":52244864,"uuid":"1329931","full_name":"insin/newforms","owner":"insin","description":"Isomorphic form-handling for React","archived":false,"fork":false,"pushed_at":"2017-08-31T01:18:54.000Z","size":6850,"stargazers_count":640,"open_issues_count":55,"forks_count":47,"subscribers_count":23,"default_branch":"react","last_synced_at":"2025-04-12T23:42:40.535Z","etag":null,"topics":["unmaintained"],"latest_commit_sha":null,"homepage":"http://newforms.readthedocs.org/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/insin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-02-04T23:05:01.000Z","updated_at":"2025-03-20T12:50:43.000Z","dependencies_parsed_at":"2022-08-30T19:52:06.868Z","dependency_job_id":null,"html_url":"https://github.com/insin/newforms","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insin%2Fnewforms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insin%2Fnewforms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insin%2Fnewforms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insin%2Fnewforms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/insin","download_url":"https://codeload.github.com/insin/newforms/tar.gz/refs/heads/react","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647255,"owners_count":21139081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["unmaintained"],"created_at":"2024-07-30T17:01:20.167Z","updated_at":"2025-04-12T23:42:45.875Z","avatar_url":"https://github.com/insin.png","language":"JavaScript","readme":"# newforms [![travis status](https://secure.travis-ci.org/insin/newforms.png)](http://travis-ci.org/insin/newforms)\n\nAn isomorphic form-handling library for [React](http://facebook.github.io/react/).\n\n(Formerly a direct port of the [Django](http://www.djangoproject.com) framework's `django.forms` library)\n\n## Other React Form Libraries\n\n* [react-formal](https://github.com/jquense/react-formal) - uses a schema and leverages React's context feature to make it really simple to render fields and error messages\n\n* [redux-form](https://github.com/erikras/redux-form) - manages form state for you, leaving you do the rendering exactly as you wish\n\n## Getting newforms\n\n### Node.js\n\nNewforms can be used on the server, or bundled for the client using an\nnpm-compatible packaging system such as [Browserify](http://browserify.org/) or\n[webpack](http://webpack.github.io/).\n\n```\nnpm install newforms\n```\n\n```javascript\nvar forms = require('newforms')\n```\n\nBy default, newforms will be in development mode. To use it in production mode,\nset the environment variable `NODE_ENV` to `'production'` when bundling. To\ncompletely remove all development mode code, use a minifier that performs\ndead-code elimination, such as [UglifyJS](https://github.com/mishoo/UglifyJS2).\n\n### Browser bundle\n\nThe browser bundle exposes a global `forms` variable and expects to\nfind global `React` variable to work with.\n\nThe uncompressed bundle is in development mode, so will log warnings about\npotential mistakes.\n\nYou can find it in the [/dist directory](https://github.com/insin/newforms/tree/v0.13.2/dist).\n\n## [Upgrade Guide](https://github.com/insin/newforms/blob/react/UPGRADE_GUIDE.md#0130)\n\n## [Documentation @ ReadTheDocs](http://newforms.readthedocs.org/en/v0.13.2/)\n\n## [Newforms Examples @ GitHub](https://github.com/insin/newforms-examples)\n\n## Related Projects\n\n* [newforms-bootstrap](https://github.com/insin/newforms-bootstrap) - Bootstrap 3\n  integration \u0026 grid form form layout components.\n\n* [newforms-gridforms](https://github.com/insin/newforms-gridforms) -\n  [Grid Forms](http://kumailht.com/gridforms/) form layout components.\n\n## Quick Guide\n\nA quick introduction to defining and using newforms Form objects.\n\n### Design your Form\n\nThe starting point for defining your own forms is `Form.extend()`.\n\nHere's a simple (but incomplete!) definition of a type of Form you've probably\nseen dozens of times:\n\n```javascript\nvar SignupForm = forms.Form.extend({\n  username: forms.CharField(),\n  email: forms.EmailField(),\n  password: forms.CharField({widget: forms.PasswordInput}),\n  confirmPassword: forms.CharField({widget: forms.PasswordInput}),\n  acceptTerms: forms.BooleanField({required: true})\n})\n```\n\nA piece of user input data is represented by a `Field`, groups\nof related Fields are held in a `Form` and a form input which will\nbe displayed to the user is represented by a `Widget`. Every\nField has a default Widget, which can be overridden.\n\n### Rendering a Form\n\nForms provide helpers for rendering labels, user inputs and validation errors\nfor their fields. To get you started quickly, newforms provides a React\ncomponent which use these helpers to render a basic form structure.\n\nAt the very least, you must wrap rendered form contents in a `\u003cform\u003e`,\nprovide form controls such as a submit button and hook up handling of form\nsubmission:\n\n```javascript\nvar Signup = React.createClass({\n  render: function() {\n    return \u003cform onSubmit={this._onSubmit}\u003e\n      \u003cforms.RenderForm form={SignupForm} ref=\"signupForm\"/\u003e\n      \u003cbutton\u003eSign Up\u003c/button\u003e\n    \u003c/form\u003e\n  },\n\n  // ...\n```\n\nRendering helpers attach event handlers to the inputs they render, so getting\nuser input data is handled for you.\n\nThe `RenderForm` component handles creating a form instance for you, and\nsetting up automatic validation of user input as it's given.\n\nTo access this form instance later, make sure the component has a `ref` name.\n\n### Handling form submission\n\nThe final step in using a Form is validating when the user attempts to submit.\n\nFirst, use the `ref` name you defined earlier to get the form instance via the\n`RenderForm` component's `getForm()` method.\n\nThen call the form's `validate()` method to ensure every field in the form is\nvalidated against its current user input.\n\nIf a Form is valid, it will have a `cleanedData` object containing validated\ndata, coerced to the appropriate JavaScript data type when appropriate:\n\n```javascript\n  propTypes: {\n    onSignup: React.PropTypes.func.isRequired\n  },\n\n  _onSubmit: function(e) {\n    e.preventDefault()\n\n    var form = this.refs.signupForm.getForm()\n    var isValid = form.validate()\n    if (isValid) {\n      this.props.onSignup(form.cleanedData)\n    }\n  }\n})\n```\n\n### Implementing custom validation\n\nThere's an obvious validation not being handled by our form: what if the\npasswords don't match?\n\nThis is a cross-field validation. To implement custom, cross-field validation\nadd a `clean()` method to the Form definition:\n\n```javascript\nclean: function() {\n  if (this.cleanedData.password \u0026\u0026\n      this.cleanedData.confirmPassword \u0026\u0026\n      this.cleanedData.password != this.cleanedData.confirmPassword) {\n    throw forms.ValidationError('Passwords do not match.')\n  }\n}\n```\n\n### [Live Quickstart Demo](http://newforms.readthedocs.org/en/latest/quickstart.html#live-demo)\n\n## MIT Licensed\n","funding_links":[],"categories":["Awesome React","Uncategorized","JavaScript","Code Design"],"sub_categories":["Resources","Uncategorized","Form Logic"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finsin%2Fnewforms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finsin%2Fnewforms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finsin%2Fnewforms/lists"}