/** * Created by YS on 2016/10/31. */ import { FormButton, submittable } from './buttons'; import * as React from 'react'; import {ConfigProps, InjectedFormProps,BaseFieldProps, reset} from 'redux-form' import {WidgetProps} from "./field"; import {renderFields} from "./render-fields"; import { getDecorator } from './decorate'; export type Options = {name:string,value:any}[] export type AsyncOptions = ()=>Promise export type RuntimeAsyncOptions = (value:any, props?:WidgetProps)=>(Promise|Options) export type FieldListens={ /** * q:what is valuePath here? * a: * If your formValue is {"foo":{"haha":[{"bar":10032}]}}, then the callback here will receive these arguments: * 10032, {bar:10032}, [{bar:10032}], {haha:[{bar:10032}]}, {foo:...} */ to:string|string[]|((keyPath:string)=>string), then:(value?:any|any[],formValue?:any,dispatch?:any)=>Partial|Promise&{value:any}>|void; }[] export interface WidgetInjectedProps{ hide?:boolean, multiple?:boolean, placeholder?:any, fullWidth?:boolean, //todo: should I put this presentation logic here? required?:boolean, disabled?:boolean, defaultValue?:any style?:React.CSSProperties, [propName:string]:any } export interface FormFieldSchema extends Partial,Partial{ key:string, label:string, type: string | React.ComponentClass | React.StatelessComponent, children?:FormFieldSchema[] options?:Options | AsyncOptions | RuntimeAsyncOptions, /** * keyPath will keyPath from the root of the form to your deeply nested field. e.g. foo.bar[1].far */ listens?:FieldListens, } @getDecorator() export class ReduxSchemaForm extends React.PureComponent{ reset=()=>this.props.dispatch(reset(this.props.form)) render(){ const formClass = this.props.classes&&this.props.classes.form?this.props.classes.form:"" return
{renderFields( this.props.form, this.props.schema )} {this.props.children?
{this.props.children}
:null} { (!this.props.noButton)?
提交 重置
:
} } } type ReduxSchemaFormOwnProps = { schema:FormFieldSchema[], noButton?:boolean, classes?:any, dispatch?:(...args:any[])=>any, disableResubmit?:boolean } type ReduxSchemaFormProps = Partial>&ReduxSchemaFormOwnProps