1.0.26 • Published 8 months ago

react-native-form-builder-pro v1.0.26

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

react-native-form-builder

A simple and fully customizable React Native component that help to desing form.

  • Form is displayed inside of a customizable ScrollView.
  • Customizable buttons and controlled function of form are displayed at the bottom of the Form.
Screenshot 1Screenshot 2Screenshot 3Screenshot 4Screenshot 5
npm.ionpm.ionpm.ionpm.ionpm.io

Installation

If using yarn:

yarn add react-native-form-builder-pro

If using npm:

npm i react-native-form-builder-pro

Dependencies

    "expo-document-picker",
    "expo-image-manipulator",
    "expo-image-picker",
    "moment",
    "native-base",
    "prop-types",
    "react-native-modal-datetime-picker",
    "react-native-select-two"

Usage

import { Builder, FormEvents } from "react-native-form-builder-pro";

Simply place a <Builder /> tag with required parameter.

<View style={{flex: 1}}>
    <Builder
        fields={this.props.fields}
        dropdowns={this.props.dropdowns}
        onFormEvent={this.onFormEvent.bind(this, "form")}
        values={this.props.values}
        isFileUploading={this.props.fetching}
        onDatePickerPress={(uid, showTime) =>
        this.props.toggleDateTimePicker(
          uid,
          showTime ? 'datetime' : 'date'
        )}
      formValidationErrors={
        this.props.formValidationErrors
      }
      submitButtonStyle={styles.submitButtonStyle}
      submitButtonText={this.objectId ? 'Update' : 'Submit' }
    />
    <DateTimePicker
        isVisible={true} 
        onConfirm={date => {
            console.log(date)
        }}
        onCancel={() => console.log("cancel")}
        mode={"date"}
        minuteInterval={30}
    />
</View>

Documentation

Form Builder Props

NameDescriptionRequiredType
fieldsInput that want to be displayYesArray
dropdownsRelated select boxNoObject
valuesPrefilled valuesNoArray
isFileUploadingLoading when file is uploadingNoBoolean
submitButtonStyleSubmit Button StylingNoStyle
submitButtonTextSubmit Button TextNoString

Support Field Format

"fields": [
    {
      "label": "Qns",
      "name": "form_name_1",
      "options": [
        Object
      ],
      "rules": "required",
      "type": "select_multiple"
    },
    {
      "label": "Name",
      "name": "form_name_2",
      "rules": "required",
      "type": "text"
    },
    {
      "label": "Discription",
      "name": "form_name_3",
      "rules": "required",
      "type": "text_area"
    },
    {
      "label": "photo",
      "name": "form_name_4",
      "rules": "required",
      "type": "image"
    },
    {
      "label": "Documents",
      "name": "form_name_5",
      "rules": "required",
      "type": "file"
    },
    {
      "label": "Mobile No",
      "name": "form_name_6",
      "rules": "required",
      "type": "number"
    },
    {
      "label": "Date of Birth",
      "name": "form_name_7",
      "rules": "required",
      "type": "date"
    },
    {
      "label": "What is the best options",
      "name": "form_name_8",
      "options": [
        Object
      ],
      "rules": "required",
      "type": "checkbox"
    },
    {
      "label": "What is the correct answer?",
      "name": "form_name_9",
      "options": [
        Object
      ],
      "rules": "required",
      "type": "multiple_checkbox"
    },
    {
      "label": "Which one is red color?",
      "name": "form_name_10",
      "options": [
        Object
      ],
      "rules": "required",
      "type": "select_dropdown"
    }
  ]

For Populate/Prefilled Value Example

Key name will be fields name as above :
 {
  "form_name_1": [0:A], //array
  "form_name_2": "Yogesh", // string
  "form_name_3": "Yogesh", // string
  "form_name_4": [{
                download_link:uploads/1623238864Adobe Scan 09 Jan 2021 (1).pdf
                original_name:Adobe Scan 09 Jan 2021 (1).pdf},
                {
                download_link:uploads/1623571260Adobe Scan 09 Jan 2021 (1).pdf
                original_name:Adobe Scan 09 Jan 2022 (1).pdf
                }], // array object
  "form_name_5": "download_link:uploads/1623571260Adobe Scan 09 Jan 2021 (1).pdf", // string
  "form_name_6": "9999332859", // string
  "form_name_7": "2021-06-09", // string
  "form_name_8": "option2", // string
  "form_name_9": [0:H,1:K], // array
  "form_name_10": "Red" // string
}

Form Event

FormEvents = {
  OnValueUpdate: "on_value_update",
  OnFileUploadRequest: "on_file_upload_request",
  SubmitRequest: "on_submit_button_click",
  CancelRequest: "on_cancel_button_click",
  ErrorInForm: "error_in_form",
  OnActionButtonClick: "on_action_button_click"
};

Form Action Control Function

onFormEvent = (formType, eventType, args) => {
    switch (eventType) {
      case FormEvents.OnValueUpdate:
        console.log(FormEvents.OnValueUpdate);
        break;
      case FormEvents.ErrorInForm:
        console.log(args.err);
        break;
      case FormEvents.OnActionButtonClick:
        console.log("action button", args.action);
        break;
      case FormEvents.SubmitRequest:
        console.log("Handle Submit Request");
        break;
      case FormEvents.CancelRequest:
        console.log('Handle Cancel Button Request');
        break;
    }
  };

Author

Yogesh Chauhan

1.0.26

8 months ago

1.0.25

8 months ago

1.0.24

8 months ago

1.0.22

2 years ago

1.0.23

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago