react-fractal-field
v4.0.0
Published
predictable react router
Maintainers
Readme
react-fractal-field
$ npm install prop-types lodash react react-fractal-field --saveUsage
import { Field, FieldSet } from 'react-fractal-field';
const MyComponent = ({ onSubmit }) => (
<FieldSet onSubmit={onSubmit} isolated>
{({ triggerSubmit }) => (
<div>
<Field name="value">
{({ control }) => (
<div>
<input {...control} type="text" />
</div>
)}
</Field>
<button onClick={triggerSubmit}>Submit</button>
</div>
)}
</FieldSet>
)API
common FieldSet/FieldList/Field props:
id: [ String, Number ] - ID used for remote controlling this field/form (nullby default)softTypes: [ Boolean ] - disable type checking. HIGHLY NOT RECOMMENDED!isolated: [ Boolean ] - if true meta/value stopped from sharing between parentname: [ String, Number ] - need for value bindingvalue: [String, Boolean, Number, Array, Object, Null]initialValue: [String, Boolean, Number, Array, Object, Null] - values that will be provided for child fields (useful only for forms)onChange: [ Function ] - handler that will be called on every field value changesonValueChange: [ Function ] - handler that will be called on every field changesvalidate: [ Function ] - validation function/array . if error it need to return the error-message stringonChangeValidity: [ Function ]postponeInvalid: [ Boolean ]form: [ Boolean ]onSubmit: [ Function ] - handler that will be called ontriggerSubmitonly in valid form stateexceptionMessage: [ Any ] - error message in case validate/normalize/format throws the errorchildren: [ Function ] - obviously, content of field/formautoClean: [ Boolean ]debug: [ Boolean ]
Field props:
normalize: [ Function ] - filter value before call onChange/onSubmit/validate callbackformat: [ Function ] - filter value before rendering (or set value to child field). from outer format to inner format
Common FieldSet/FieldList/Field children function params:
triggerChange: [ Function ] - call when you want to trigger change field by some casetriggerReset: [ Function ] - call when you want to trigger submit, obviousvalue: [ Any ]touched: [ Boolean ] - true when field or some child field was changed oncepristine: [ Boolean ] - true when field or some child field was not changed oncesubmitted: [ Boolean ] - when this form/field of parent was submitted oncevalid: [ Boolean ] - true if children and this field has no errorsinvalid: [ Boolean ] - true if children and this field/children has errorshasException: [ Boolean ] - true if children and this field/children has exceptionserror: [ Any ] - first error are not false, that returned from validate functioninvalidChildren: [ Array ] - ids of closest children with errorsactive: [ Boolean ] - true if field/children is focusing right nowactivated: [ Boolean ] - true if field/children was focused onceform: [ Object ] - Props of closest isolated form (or field itself)
Common FieldSet/FieldList/Field children function params when props.form is true:
triggerSubmit: [ Function ] - call when you want to trigger submit, obvioussubmitSuccess: [ Boolean ] - state of submittingsubmitFailed: [ Boolean ] - state of submittingsubmitting: [ Boolean ] - state of submit processing. in pending (if onSubmit returns the Promise object)submitted: [ Boolean ] - true if form was submitted oncesubmittedTimes: [ Number ] - count oftriggerSubmitcallingsubmitErrors- Any - payload of submitting
Field children function params
control: { value, onChange, onBlur, onFocus }- shortcut for putting it into control component (only for components without children fractal-fields)
FieldList children function params:
removeItems: [ Function ]appendItems: [ Function ]prependItems: [ Function ]items: [ Array ]
Remote api
triggerSubmit(id)triggerChange(id)onError(callback)
