Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
react-form
Advanced tools
react-form is a lightweight, opinionated form-building system for React. The react-form DSL was designed to produce clean code that directly resembles an underlying object hierarchy.
Install react-form, react-form-inputs:
npm install --save react-form react-form-inputs
Basic usage example (JSX+ES6):
var React = require('react');
var {Form, Input} = require('react-form');
var {Password, Text} = require('react-form-inputs');
var LoginForm = React.createClass({
render() {
return (
<Form {...this.props} for="user">
<h1>Login</h1>
<Input type={Text} for="username" placeholder="Username" />
<Input type={Password} for="password" placeholder="Password" />
<input type="submit" value="Login" />
</Form>
);
}
});
var user = {
username: null,
password: null
};
React.render(<LoginForm object={user} />, document.getElementById('login'));
react-form ships with an example application - try it out:
cd example
npm install
npm link ../
node app
#Open http://localhost:3000
react-form uses a context-based materialized path system to track and propagate object changes.
The Form, Inputs, and Input components expose interfaces to easily reference nodes anywhere in an object hierarchy. Each of the aforementioned components represents a "path segment."
Each of these components exposes
Form is a required outer container component. Form components are responsible for maintaining state and propagating changes. Form exposes event interfaces for advanced integration with a parent application, Store, component, etc.
Form has several configurable props:
String
- Namespace for a Form instance. Used to generate input names. Defaults to "object."Object
- Object used to hydrate input fields. Defaults to "{}."Function(event)
- Called when Form instance is submitted.Function(path, value)
- Called when a nested Input at path undergoes a value change to value. NOTE: Supplying this handler disables internal Form state management; onUpdate must replace props.object to trigger a rerender.Tip: When implementing a custom onUpdate or onSubmit handler, use objectPath and this.getValue() to negotiate object changes.
Inputs is a nested container element. Inputs is required to reference nested objects and arrays of objects. Inputs is not utilized in simple, single-tier models.
When referencing an Array of objects, all children are duplicated and mapped to each array element.
Inputs has two user-configurable props:
String
- Required path segment. Must reference an object or array of objects.String
- Optionally used to override "name" attributes of nested components.Example:
var {Form, Inputs} = require('react-form');
var gizmo = { //path: []
widgets: [ //path: [widgets] <-- INPUTS
{ color: "Red" }, //path: [widgets, 0, color]
{ color: "Blue" } //path: [widgets, 1, color]
//...
<Form for="gizmo" object={gizmo}>
<Inputs for="widgets"> //in this example, children will be duplicated twice
Input is the most commonly-used component. Input is used to render form controls, each varying in function and complexity.
Input requires API-compliant, pluggable components known as "types." For flexibility, no Input types ship with react-form. A number of useful, common components can be found in react-form-inputs.
Input has three universally-applicable props:
Input type
- Required, API-compliant component to render.String
- Required path segment. Must reference a value appropriate for given Input type.String
- Optionally used to override generated Input "name."See type-specific documentation for respective Input types for additional, configurable props.
Example:
var React = require('react');
var {Form} = require('react-form');
var Text = require('react-form-inputs/text');
var gizmo = { //path: []
name: "Foo" //path: [name]
//...
<rf.Form for="gizmo" object={gizmo}>
<rf.Input type={Text} for="name" /> //Initial value of "Foo"
Documentation regarding the built-in addon system will be provided in an upcoming release. Optional addons enabling conformity with Rails-conventions, field label generation, and error handling are in development.
Presently, react-form APIs are highly unstable, untested, and explosive!
Run tests:
npm test
Link a dependent project:
#Within dependent project directory...
npm link ~/path-to-react-form/
The react-form DSL was heavily inspired by (stolen from) Formtastic.
react-form is released under the MIT License.
FAQs
⚛️ 💼 React hooks for managing form state and lifecycle
The npm package react-form receives a total of 6,751 weekly downloads. As such, react-form popularity was classified as popular.
We found that react-form demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.