简体   繁体   中英

how can i use react form builder 2 in react js project

I have been trying to use react form builder 2 for my project but i cannot understand how to require it and then display form through it can anyone help please iam new at react js and in the past i have been just importing the library after installing but in this case i dont have the tags to import iam finding it difficult to use it.?

basic usage
var React = require('react');
var FormBuilder = require('react-form-builder2');

React.render(
  <FormBuilder.ReactFormBuilder />,
  document.body
)
Props
var items = [{
  key: 'Header',
  name: 'Header Text',
  icon: 'fa fa-header',
  static: true,
  content: 'Placeholder Text...'
},
{
  key: 'Paragraph',
  name: 'Paragraph',
  static: true,
  icon: 'fa fa-paragraph',
  content: 'Placeholder Text...'
}];

<FormBuilder.ReactFormBuilder
  url='path/to/GET/initial.json'
  toolbarItems={items}
  saveUrl='path/to/POST/built/form.json' />
React Form Generator
Now that a form is built and saved, let's generate it from the saved json.

var React = require('react');
var FormBuilder = require('react-form-builder2');

React.render(
  <FormBuilder.ReactFormGenerator
    form_action="/path/to/form/submit"
    form_method="POST"
    task_id={12} // Used to submit a hidden variable with the id to the form from the database.
    answer_data={JSON_ANSWERS} // Answer data, only used if loading a pre-existing form with values.
    authenticity_token={AUTH_TOKEN} // If using Rails and need an auth token to submit form.
    data={JSON_QUESTION_DATA} // Question data
  />,
  document.body
)

Try with https://github.com/rjsf-team/react-jsonschema-form you can choose the design of output. and if you need a visual builder, you can use my project https://github.com/MedinaGitHub/react-jsonschema-form-builder

You should add bootstrap & font-awesome style sheets to index.html https://github.com/Kiho/react-form-builder/blob/master/public/index.html#L5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM