0.6.12 • Published 4 years ago

@heartfulnessinstitute/react-hfn-forms v0.6.12

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

react-hfn-forms

Exports

import DynamicForm from '@heartfulnessinstitute/react-hfn-forms'

    <DynamicForm
      key={this.state.current.id}
      formClassName="form"
      formTitle={this.state.useLayout ? "Demo with Layout" : "Demo without Layout"}
      formLayout={this.state.useLayout ? layout : null}
      defaultValues={this.state.current}
      formFields={[
        { name: "name", label: "Name", props: { required: true } },
        { name: "age", label: "Age", type: "number", defaultValue: 5, },
        { name: "rating", label: "Rating", type: "number", props: { min: 0, max: 5 }},
        { name: "gender", label: "Gender", type: "radio", options: gender_options },
        { name: "qualification", label: "Qualification" },
        { name: "country", label: "Country", type: "select", options: countries_options },
        {
          name: "states", label: "States", type: "multiselect", options: [],
          dynamic: (r) => (r.country === 'India' ? { options: states_india } : { options: states_us })
        },
        { name: "date", label: "Start Date", type: "date", props: {maxDate: "2019-12-22"} },
        { name: "enddate", label: "End Date", type: "date", props: { minDate: "2019-10-22" } },

      ]}
      onSubmit={model => {
        this.onSubmit(model);
      }}
      onDiscard={() => this.setState({ current: {}})}
    />

import DynamicTable from '@heartfulnessinstitute/react-hfn-forms/DynamicTable'

    <DynamicTable
      table_columns={table_columns}
      table_style={{rTableCell: {padding: "10px"}}}
      paneLayout={paneLayout}
      renderRecord={renderRecord}
      data={this.state.data}
      allow={{ create: true, delete: true, update: true }}
      buttons={{createButton, deleteButton, editButton, submitButton }}
      form_props={{ formFields, formLayout }}
      onCUD={this.onCUD}
      table_edit_inline={true}
    />

    table_columns = [
        { name: 'name', label: "Name" },
        { name: 'gender' , label: "Gender", transform: "gender" },
        { name: 'date', label: "Start Date",  transform: "shortdate" }
    ];

    formFields = [
        { name: "name", label: "Name", props: { required: true } },
        { name: "age", label: "Age", type: "number", defaultValue: 5, },
        { name: "rating", label: "Rating", type: "number", props: { min: 0, max: 5 }},
        { name: "gender", label: "Gender", type: "radio", options: gender_options },
        { name: "qualification", label: "Qualification" },
        { name: "country", label: "Country", type: "select", options: countries_options },
        {
          name: "states", label: "States", type: "multiselect", options: [],
          dynamic: (r) => (r.country === 'India' ? { options: states_india } : { options: states_us })
        },
        { name: "date", label: "Start Date", type: "date", props: {maxDate: "2019-12-22"} },
        { name: "enddate", label: "End Date", type: "date", props: { minDate: "2019-10-22" } },

      ]

For detailed usage of DynamicForm and DynamicTable, see the code in the examples folder.

Choice Lists

The following lists could be passed as options for dropdown/radio/multiselect fields

gender_options - male, female, unspecified countries - list of countries indiastates - list of indian states and union territories

The format of each entry in the above lists is a dict with the keys name, label and value. e.g., gender_options is defined as follows:

[
    { name: "M", label: "Male", value: "M" },
    { name: "F", label: "Female", value: "F" },
    { name: "U", label: "Unspecified", value: "U" },
]

Validators

validateEmail(string) - returns true if the given string is a valid email validatePhoneNumber(string) - returns true if the given string is a valid phonenumber (according to google phoneutil lib)

validatePNR(string) - returns true if given string is a valid registrations PNR (Heartfulness specific) validateAbhyasiId(string) - returns true if given string is a valid Heartfulness ID (Heartfulness specific)

validateRE(regex, string) = returns true if the given string matches the given regex

Formatting Helpers

formatSys2MomentDate(date_object) = returns the string in moment format date(Dec 31, 2019 23:01:59) => str(20191231230159)

formatSys2ShortDate(date_object) - returns the string in short format date(Dec 31, 2019 23:01:59) => str(Dec 31, 2019) or str(Dec 31) if current year is 2019

formatSys2OdooDate(date_object) - returns the string in odoo date format date(Dec 31, 2019 23:01:59) => str(2019-12-31)

formatOdooDate2Sys(string) - returns the date object given a string in odoo date format str(2019-12-31) => date(Dec 31, 2019 23:01:59)

doFormatShortDate(string) - returns the string in short format given odoo date string str(2019-12-31) => str(Dec 31, 2019) or str(Dec 31) if current year is 2019

doFormatYesNo(boolean) - returns the string yes or no given a boolean value TRUE => yes FALSE => no

doFormatTitle(string) - returns the string in Title case andhRA praDEsh => Andhra Pradesh

doFormatLower(string) - returns the string in Lower case andhRA praDEsh => andhra pradesh

doFormatUpper(string) - returns the string in Upper case andhRA praDEsh => ANDHRA PRADESH

doFormatGender(string) - returns full name in string given the gender value M, F, or U M => Male F => Female U => Not Mentioned

JSON Files

monthnames.json

indiastates.json

countries.json

Setup

# npm i @heartfulnessinstitute/react-hfn-forms -S
0.6.12

4 years ago

0.6.11

4 years ago

0.6.7

4 years ago

0.6.6

4 years ago

0.6.9

4 years ago

0.6.8

4 years ago

0.6.10

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.5

4 years ago

0.6.4

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.8

4 years ago

0.5.7

4 years ago

0.5.6

5 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.74

5 years ago

0.4.73

5 years ago

0.4.72

5 years ago

0.4.71

5 years ago

0.4.70

5 years ago

0.4.65

5 years ago

0.4.68

5 years ago

0.4.69

5 years ago

0.4.66

5 years ago

0.4.67

5 years ago

0.4.64

5 years ago

0.4.63

5 years ago

0.4.62

5 years ago

0.4.61

5 years ago

0.4.60

5 years ago

0.4.58

5 years ago

0.4.57

5 years ago

0.4.55

5 years ago

0.4.56

5 years ago

0.4.54

5 years ago

0.4.52

5 years ago

0.4.49

5 years ago

0.4.51

5 years ago

0.4.50

5 years ago

0.4.48

5 years ago

0.4.47

5 years ago

0.4.46

5 years ago

0.4.45

5 years ago

0.4.44

5 years ago

0.4.43

5 years ago

0.4.42

5 years ago

0.4.40

5 years ago

0.4.39

5 years ago

0.4.38

5 years ago

0.4.37

5 years ago

0.4.36

5 years ago

0.4.35

5 years ago

0.4.34

5 years ago

0.4.33

5 years ago

0.4.32

5 years ago

0.4.31

5 years ago

0.4.30

5 years ago

0.4.28

5 years ago

0.4.29

5 years ago

0.4.27

5 years ago

0.4.26

5 years ago

0.4.25

5 years ago

0.4.23

5 years ago

0.4.21

5 years ago

0.4.20

5 years ago

0.4.19

5 years ago

0.4.18

5 years ago

0.4.17

5 years ago

0.4.16

5 years ago

0.4.11

5 years ago

0.4.12

5 years ago

0.4.9

5 years ago

0.4.8

5 years ago

0.4.7

5 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.3

5 years ago

0.4.2

6 years ago

0.4.0

6 years ago

0.3.9

6 years ago

0.3.8

6 years ago

0.3.7

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.1-2

6 years ago

0.0.1-1

6 years ago

0.0.1-0

6 years ago