项目作者: zubairpaizer

项目描述 :
React Form Builder
高级语言: JavaScript
项目地址: git://github.com/zubairpaizer/zubair-react-form-builder.git
创建时间: 2018-02-19T09:48:13Z
项目社区:https://github.com/zubairpaizer/zubair-react-form-builder

开源协议:MIT License

下载


npm package
Build Status

Zubair React From Builder

Zubair React Form Builder help you to build forms with drag and drop you can also inject your own component.

Installation

  1. npm i zubair-react-form-builder
  2. import { FormContainer, ToolBox } from 'zubair-react-form-builder';

FormContainer Props

  1. custom : Array
  2. onSave(form) : Function
  3. updateForm(callback) : Function
  4. updateOnMount : Boolean
  5. debug : Boolean
  6. loader: Boolean // set save button on loading state

// Note OnSave Props also turn on Save Button on

ToolBox Props

  1. custom : Array

Example

You can pass custom components to the form builder

  1. const myCustoms = [
  2. {
  3. container : < ContainerComponent/>,
  4. preview : < PreviewComponent/>,
  5. toolbox : {
  6. title : 'Component',
  7. icon : 'fa fa-user',
  8. name : 'CUSTOM_COM'
  9. },
  10. states : {
  11. toolType: 'CUSTOM_COM',
  12. num1 : 1,
  13. num2 : 2
  14. }
  15. }
  16. ]
  17.  
  18. class App extends React.Component {
  19. render(){
  20. /* Simply pass myCustoms to */
  21. < ToolBox custom={ myCustoms } />
  22. }
  23.  
  24. save(form){
  25. // you will receive form
  26. console.log(form);
  27. }
  28.  
  29. updateForm(callback){
  30. // fetch form and set it to callback
  31. let form = axios.......
  32. callback(form)
  33. }
  34. }

Required Props Methods Of Custom Component

  1. this.props.changeState(state, this.props.index)

  2. this.props.removeField(index)

Example Props Methods

  1. // on change state
  2. changeValue(stateFor, value){
  3. switch (stateFor){
  4. case "TITLE" :
  5. this.setState( { title : value } )
  6. break;
  7. default:
  8. return;
  9. };
  10. setTimeout(() => {
  11. return this.props.changeState(this.state, this.props.index);
  12. }, 0)
  13. }
  14.  
  15.  
  16. this.changeValue('TITLE', e.target.value)} />
  17.  
  18. // on remove field
  19. this.props.removeField(this.props.index)}>x
  20.