{"id":13499709,"url":"https://github.com/indix/formland","last_synced_at":"2025-04-11T12:30:54.579Z","repository":{"id":47442829,"uuid":"112691429","full_name":"indix/formland","owner":"indix","description":"A simple, super-flexible, extensible config based form generator for React.","archived":false,"fork":false,"pushed_at":"2019-07-22T04:31:47.000Z","size":1102,"stargazers_count":35,"open_issues_count":2,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T09:40:41.413Z","etag":null,"topics":["form-generator","react","react-forms"],"latest_commit_sha":null,"homepage":"https://oss.indix.com/formland/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/indix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-01T03:38:51.000Z","updated_at":"2025-03-12T19:38:52.000Z","dependencies_parsed_at":"2022-08-22T20:50:25.073Z","dependency_job_id":null,"html_url":"https://github.com/indix/formland","commit_stats":null,"previous_names":["praneshr/react-form"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indix%2Fformland","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indix%2Fformland/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indix%2Fformland/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indix%2Fformland/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/indix","download_url":"https://codeload.github.com/indix/formland/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248401934,"owners_count":21097328,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["form-generator","react","react-forms"],"created_at":"2024-07-31T22:00:39.032Z","updated_at":"2025-04-11T12:30:54.192Z","avatar_url":"https://github.com/indix.png","language":"TypeScript","readme":"![Logo](https://image.ibb.co/iF9Doe/formland.png)\n\n[![Build Status](https://travis-ci.org/indix/formland.svg?branch=master)](https://travis-ci.org/indix/formland)\n[![npm version](https://badge.fury.io/js/formland.svg)](https://badge.fury.io/js/formland)\n\nA simple, super-flexible, extensible config based form generator for React.\n\n## Features\n\n* Super-flexible\n* Config based form element creation\n* Take super control over all the form elements\n* Use third party components as form element\n\n## Install\n\n```bash\n  npm i formland\n\n  # or\n\n  yarn add formland\n```\n\n## Usage\n\n```javascript\nimport 'formland/css/index.css'\nimport React, { Component } from 'react'\nimport Form from 'formland'\n\nclass Example extends Component {\n  constructor() {\n    super()\n    this.state = {}\n    this.onChange = this.onChange.bind(this)\n  }\n\n  onChange(newState) {\n    this.setState(newState)\n  }\n\n  render() {\n    const config = [\n      {\n        id: 'firstName',\n        type: 'text',\n        displayName: 'First Name',\n        resultPath: 'name.firstName',\n        placeholder: 'Enter your first name',\n      },\n    ]\n\n    return \u003cForm config={config} store={this.state} onChange={this.onChange} /\u003e\n  }\n}\n```\n\n## Props\n\n| Property                 | Type                         | Default   | Description                                                         |\n| ------------------------ | ---------------------------- | --------- | ------------------------------------------------------------------- |\n| config                   | array                        | []        | Config to populate form elements.                                   |\n| store                    | object \\| array              | {}        | The data store to read the values from.                             |\n| onChange                 | function                     | undefined | Callback for `onChange` event                                       |\n| onBlur                   | function                     | undefined | Callback for `onBlur` event                                         |\n| onFocus                  | function                     | undefined | Callback fro `onFocus` event                                        |\n| customComponentResolvers | array                        | undefined | Array of resolvers to resolve custom form elements                  |\n| customValueResolvers     | array                        | undefined | Array of resolvers to resolve the value of the custom form elements |\n| useNativeEvent           | boolean                      | false     | Whether to return the new state or native JS event object on events |\n| primaryButton            | string \\| false \\| undefined | 'Submit'  | Title for the primary button. `false` to remove button              |\n| secondaryButton          | string \\| false \\| undefined | 'Cancel'  | Title for the secondary button. `false` to remove button            |\n| onSecondaryButtonClick   | function                     | `()=\u003e {}` | onClick event handler for secondary button                          |\n\n## Configuration File Properties\n\n| Property                | Type     | Default   | Description                                                                                                                                                                                                                                                                     |\n| ----------------------- | -------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| id                      | string   | undefined | ID for each form field. This should be unique.                                                                                                                                                                                                                                  |\n| type                    | string   | undefined | Type of the form field to be generated. The native package supports `text`, `color`, `date`, `email`, `month`, `number`, `tel`, `time`, `url`, `week`, `toggle`, `radio`, `checkbox`, `range`, `textarea`, `dropdown` types. New types can be added via `Custom Form Elements`. |\n| resultPath              | string   | undefined | A [dot-prop-immutable](https://github.com/debitoor/dot-prop-immutable) compatible path to store the form field value.                                                                                                                                                           |\n| displayName             | string   | undefined | Display text for the form field.                                                                                                                                                                                                                                                |\n| className               | string   | undefined | ClassName for the root form field element.                                                                                                                                                                                                                                      |\n| isHidden                | function | undefined | Method to hide form field element in runtime. `(store) =\u003e boolean`                                                                                                                                                                                                              |\n| optional                | boolean  | undefined | Says if the form field is optional.                                                                                                                                                                                                                                             |\n| placeholder             | string   | undefined | Placeholder text for the form elements                                                                                                                                                                                                                                          |\n| helpText                | string   | undefined | Help text for a form element                                                                                                                                                                                                                                                    |\n| helpTextOptions         | object   | undefined | See rc-tooltip [props](https://github.com/react-component/tooltip#props)                                                                                                                                                                                                        |\n| options                 | array    | []        | Array of options. `({ value: any, label: any })[]`                                                                                                                                                                                                                              |\n| separator               | string   | ','       | Separator to join/separate multiple values. Used by checkbox, multi-dropdown, etc.                                                                                                                                                                                              |\n| topComponent            | function | undefined | Method to render any additional elements to the top of the form field element. `(store) =\u003e JSX.Element`                                                                                                                                                                         |\n| simpleValues            | boolean  | false     | Handle multi values as string. Works along with `separator`.                                                                                                                                                                                                                    |\n| bottomComponent         | function | undefined | Method to render any additional elements to the bottom of the form field element. `(store) =\u003e JSX.Element`                                                                                                                                                                      |\n| componentProps          | object   | undefined | Any additional props that should be passed to the underlying form field element. For example, to make the `dropdown` multi-select, pass `componentProps: { multiple: true }`.                                                                                                   |\n| instantValidation       | boolean  | false     | Do validation on user input.                                                                                                                                                                                                                                                    |\n| required                | boolean  | false     | Make the field required.                                                                                                                                                                                                                                                        |\n| validation              | function | undefined | Method to perform validation. `(value) =\u003e errorMessage|null`                                                                                                                                                                                                                    |\n| modifyStoreBeforeChange | function | undefined | Method to modify store before `onChange` handler is called. `(config, value, store) =\u003e store`.                                                                                                                                                                                  |\n\n### Available `componentProps`\n\n#### `type: toggle`\n\n| Property | Type   | Default   | Description                                                 |\n| -------- | ------ | --------- | ----------------------------------------------------------- |\n| infoText | string | undefined | Info text to be displayed to the right of the toggle switch |\n\n#### `type: range`\n\n| Property  | Type    | Default | Description                                   |\n| --------- | ------- | ------- | --------------------------------------------- |\n| showRange | boolean | true    | Shows the `min` and `max` value of the slider |\n| showValue | boolean | true    | Shows the current range value explicitly      |\n\n## Form Groups\n\nIt is possible to group form elements. Take a look at the following example.\n\n```javascript\nimport 'formland/css/index.css'\nimport React, { Component } from 'react'\nimport Form from 'formland'\n\nclass Example extends Component {\n  constructor() {\n    super()\n    this.state = {}\n    this.onChange = this.onChange.bind(this)\n  }\n\n  onChange(newState) {\n    this.setState(newState)\n  }\n\n  render() {\n    const config = [\n      {\n        id: 'group-1',\n        type: 'group',\n        displayName: 'Group 1',\n        description: 'This is group 1',\n        elements: [\n          {\n            id: 'firstName',\n            type: 'text',\n            displayName: 'First Name',\n            resultPath: 'name.firstName',\n            placeholder: 'Enter your first name',\n          },\n          {\n            id: 'LastName',\n            type: 'text',\n            displayName: 'Last Name',\n            resultPath: 'name.LastName',\n            placeholder: 'Enter your last name',\n          },\n        ],\n      },\n      {\n        id: 'group-2',\n        type: 'group',\n        displayName: 'Group 2',\n        description: 'This is group 1',\n        elements: [\n          {\n            id: 'country',\n            type: 'text',\n            displayName: 'First Name',\n            resultPath: 'name.country',\n            placeholder: 'Enter your country',\n          },\n          {\n            id: 'state',\n            type: 'text',\n            displayName: 'Last Name',\n            resultPath: 'name.state',\n            placeholder: 'Enter your state',\n          },\n        ],\n      },\n    ]\n\n    return \u003cForm config={config} store={this.state} onChange={this.onChange} /\u003e\n  }\n}\n```\n\n## Validation\n\nValidations are done per form element. Add a `validation()` method in the form element config. Validations can be done in two ways.\n\n* Set `instantValidation: true` in the form element config. Now, the validation method will be called each time on user input.\n\n* Use `validate()` method of the form instance. This returns an array of errors, if any. Useful for conditional based approach.\n\n```javascript\nimport 'formland/css/index.css'\nimport React, { Component } from 'react'\nimport Form from 'formland'\n\nclass Example extends Component {\n  constructor() {\n    super()\n    this.state = {}\n    this.onChange = this.onChange.bind(this)\n  }\n\n  onChange(newState) {\n    this.setState(newState)\n  }\n\n  onSubmit() {\n    const errors = this.form.validate()\n    console.log(errors)\n  }\n\n  render() {\n    const config = [\n      {\n        id: 'answer',\n        type: 'text',\n        displayName: 'What is 4 + 5',\n        resultPath: 'answer',\n        placeholder: 'Answer',\n        validation: value =\u003e value !== '9' \u0026\u0026 'Wrong Answer',\n      },\n    ]\n\n    return (\n      \u003cForm\n        ref={el =\u003e (this.form = el)}\n        config={config}\n        store={this.state}\n        onChange={this.onChange}\n      /\u003e\n    )\n  }\n}\n```\n\n## Modify store value directly from config\n\nYou can access the store and change any store value directly from the config using `modifyStoreBeforeChange` method. This method will be called before `onChange` event. You can return a modified state and it will be passed to the `onChange` handler. The primary use case for this will be, to change a form value based on another form value.\n\n```javascript\nimport 'formland/css/index.css'\nimport React, { Component } from 'react'\nimport Form from 'formland'\n\nclass Example extends Component {\n  constructor() {\n    super()\n    this.state = {}\n    this.onChange = this.onChange.bind(this)\n  }\n\n  onChange(newState) {\n    this.setState(newState)\n  }\n\n  render() {\n    const config = [\n      {\n        id: 'firstName',\n        type: 'text',\n        displayName: 'First Name',\n        resultPath: 'name.firstName',\n        placeholder: 'Enter your first name',\n        modifyStoreBeforeChange: (config, value, store) =\u003e {\n          store.readonly = value\n          return store\n        },\n      },\n      {\n        id: 'readyonly',\n        type: 'text',\n        displayName: 'Output',\n        resultPath: 'readonly',\n        componentProps: {\n          disabled: true,\n        },\n      },\n    ]\n\n    return \u003cForm config={config} store={this.state} onChange={this.onChange} /\u003e\n  }\n}\n```\n\n## Custom Buttons\n\nIt is possible to add custom buttons. Just wrap your buttons with `\u003cForm\u003e`.\n\n```javascript\n\u003cForm\n  ref={el =\u003e (this.form = el)}\n  config={config}\n  store={this.state}\n  onChange={this.onChange}\n\u003e\n  \u003cbutton type=\"submit\"\u003eCustom Button\u003c/button\u003e\n\u003c/Form\u003e\n```\n\n## Custom Form Elements\n\nCustom form elements can be added to any instance of formland via `customComponentResolvers` and `customValueResolvers` props.\n\n* `customComponentResolvers(type: string) =\u003e ({ config: IReactFormConfig, value: any, callbacks: any }) =\u003e JSX.Element`\n\nReturns a valid React stateless function based on the custom type.\n\n* `customValueResolvers(config: IReactFormConfig, value: any) =\u003e any`\n\nReturns a resolved value based on the custom type.\n\nSee the following example to understand how it works.\n\n```javascript\nimport 'formland/css/index.css'\nimport React, { Component } from 'react'\nimport Select from 'react-select'\nimport Form, { getNewState } from 'formland'\n\nconst customComponentsResolver = (type) =\u003e {\n  switch(type) {\n    case 'custom-dropdown':\n      return ({ config, value = '', callbacks= {}}) =\u003e\n        \u003cSelect\n          value={value}\n          options={config.options}\n          { ...callbacks }\n          { ...config.componentProps } /\u003e\n    default:\n      return \u003cspan/\u003e\n  }\n}\n\nconst customValueResolver = (config: any, value: any) =\u003e {\n  switch (config.type) {\n    case 'react-select':\n      return value ? value.value : ''\n  }\n}\n\nclass Example extends Component {\n  constructor() {\n    super()\n    this.state = {}\n    this.onChange = this.onChange.bind(this)\n  }\n\n  onChange(newState) {\n    this.setState(newState)\n  }\n\n  render() {\n    const config = [\n      {\n        id: 'firstName',\n        type: 'custom-dropdown',\n        resultPath: 'country'\n        displayName: 'Shipping Country',\n        placeholder: 'Select a country',\n        options: [\n          {\n            value: 'india',\n            label: 'India',\n          },\n          {\n            value: 'usa',\n            label: 'The United States',\n          },\n          {\n            value: 'china',\n            label: 'China',\n          }\n        ],\n      },\n    ]\n\n    return \u003cForm\n      customComponentResolvers={[customComponentsResolver]}\n      customValueResolvers={[customValueResolver]}\n      config={config}\n      store={this.state}\n      onChange={this.onChange} /\u003e\n  }\n}\n```\n\n## Custom Form Element Packages\n\n* [formland-react-select](https://github.com/praneshr/formland-react-select) - `react-select` components for formland\n\n## Development\n\n```bash\nyarn install\nyarn build\nyarn start:examples\n```\n\nRefer `package.json` for more commands\n\n## License\n\nMIT\n","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findix%2Fformland","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Findix%2Fformland","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findix%2Fformland/lists"}