0.1.7 • Published 10 years ago

react-form-layout v0.1.7

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

react-form-layout Build Status npm version

A form layout generator for your React components.

Using bootstrap css layout by default, and custom rendering is also allowed. (e.g. section, column, field, etc)

Create <Form />

create(Field, inputPropsLookupFn, fullLayoutFn, shortLayoutFn, buttons)
ArgumentTypeExample
FieldComponent<Field name="primary" type="email" />
inputPropsLookupFnfunction:object(name) => {primary: {type: 'email' }}[name]
fullLayoutFnfunction:ReactElementrefer to __tests__/ for usage
shortLayoutFnfunction:ReactElementrefer to __tests__/ for usage
buttonsReactElement<input type="submit" />

Example Usage

let Field = class extends React.Component { render () { return <input {...this.props} />; } }, inputPropsLookupFn = (n) => { return {name: {type: 'text'}}n; }, fullLayoutFn = (builder, props) => { let {layout, section, col} = builder; return layout(props, section("Personal details", col(12, 'name') ) ); }, shortLayoutFn = fullLayoutFn, buttons = ;

let Form = create(Field, inputPropsLookupFn, fullLayoutFn, shortLayoutFn, buttons);
// <Form {...this.props} />

Configuration Props

PropTypeDescription
renderLayoutfunction:ReactElementoverriding render fn for root/layout
renderSectionfunction:ReactElementoverriding render fn for section
renderColfunction:ReactElementoverriding render fn for column
renderFieldfunction:ReactElementoverriding render fn for field
renderHiddenfunction:ReactElementoverriding render fn for hidden field
showAllbooleandetermine fulllayout/shortLayout
defaultValuesobjectinitial values for the form fiels

Helper functions

Input props lookup function

inputPropsLookup(fields, fieldName)  
ArgumentTypeExample
fieldsobject{name: {type: 'text'}, email: {type: 'email'}}
fieldNamestringname, email[0], email[1]

Input values lookup function

inputValuesLookup(values, fieldName)  
ArgumentTypeExample
valuesobject{address: [ {zip: '55555'} ]}
fieldNamestringaddress[0][zip]

Form input serialization function

formInputsSerialize(form)  
ArgumentTypeExample
formDOMNodeReactDOM.findDOMNode(this.refs.form)

License

MIT

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago