1.1.8 • Published 5 months ago

akvo-react-form-editor v1.1.8

Weekly downloads
-
License
AGPL-3.0
Repository
github
Last release
5 months ago

akvo-react-form-editor

Survey Editor for generating Akvo React Form survey definition. View Demo

Build Status Repo Size GitHub release NPM JavaScript Style Guide GitHub license Documentation Status

Install

Using NPM

npm install --save akvo-react-form-editor

Using Yarn

yarn add akvo-react-form-editor

Supported Question Type

TypeValue
Input Textinput
Input Numbernumber
Cascade Selectcascade
TextAreatext
Datedate
Optionoption
Multiple Optionmultiple_option
Tree Selecttree
Geolocationgeo
Table (Multiple Question)table
Autofield (fn string)autofield

Usage

import React from 'react';
import 'akvo-react-form-editor/dist/index.css'; /* REQUIRED */
import WebformEditor from 'akvo-react-form-editor';

const Example = () => {
  const onSave = (values) => {
    console.log(values)
  }

  render() {
    return <WebformEditor initialValue={{}} onSave={onSave} />;
  }
}

API

WebformEditor

PropsDescriptionTypeDefault
onSaveTrigger after save button clickfunction(values)-
limitQuestionTypeSupport to limit question type availableArray[QuestionType] | undefined-
defaultQuestionSupport to set custom default new question type, name and required statusObject{defaultQuestion} | undefined-
initialValueSet value by Form initialization (Required as empty object)Object{initialValue} | {}-
settingCascadeURLValue for Select Option on cascade question typeArray[settingCascadeURL] | undefined-
settingHintURLValue for Hint / Validate question settingObject{settingHintURL} | undefined-
customParamsCustom ParametersObject{customParams} | undefined

Properties

Default Question (optional)

Default question should be defined as object.

PropsDescriptionType
typeUse one of QuestionType as default new question typenumber | input | text | option | multiple_option | cascade | tree | geo
nameSet default new question title / nameString
requiredSet new question required true/false by defaultBoolean

Example:

<WebformEditor
  defaultQuestion={{
    type: 'text',
    name: 'New Question Title',
    required: true,
  }}
/>

Setting Cascade URL

Setting cascade URL should be defined as array of object. This value was used to fill Select Option value for cascade question type.

PropsDescriptionType
idUnique id as option valueInteger
nameShown as option labelString
endpointCascade APIString
initialInitial ParameterInteger | String | undefined
listObject name of arrayres.data?.[list] | res.data | String | undefined | false

Example:

<WebformEditor
  settingCascadeURL={[
    {
      id: 1,
      name: 'Province',
      endpoint:
        'http://tech-consultancy.akvo.org/akvo-flow-web-api/cascade/seap/cascade-296940912-v1.sqlite',
      initial: 0,
      list: false,
    },
  ]}
/>

Setting Hint URL

Setting Hint URL should be defined as array of object. This value was used to fill Select Option value for hint setting in a question.

Example:

<WebformEditor
  settingHintURL={{
    questionTypes: ['number'],
    settings: [
      {
        id: 1,
        name: 'JMP Explorer API',
        endpoint: 'https://jmp-explorer.akvotest.org/api/hint',
        path: [
          {
            label: 'Maximum',
            value: 'max',
          },
          {
            label: 'Minimum',
            value: 'min',
          },
          {
            label: 'Average',
            value: 'mean',
          },
          {
            label: 'Quantile 1',
            value: 'q1',
          },
          {
            label: 'Quantile 2',
            value: 'q2',
          },
          {
            label: 'Quantile 3',
            value: 'q3',
          },
        ],
      },
    ],
  }}
/>

Setting Hint URL Object

PropsDescriptionType
questionTypesValue to limit hint setting for a certain questionArray[QuestionType] | undefined
settingsValue for hint optionsArray[Settings Parameters]

Settings Parameters

PropsDescriptionType
idUnique id as option valueInteger
nameShown as option labelString
endpointHint APIString
pathHint of object path provided by API which containt the value will be shown as a hint/validationArray[Path Parameters]

Path Parameters

PropsDescriptionType
labelLabel for the path optionsString
valueValue for the path optionsString

Initial Value (optional)

Webform initial value use the same format as Akvo React Form form structure. This value was used to load a form into Akvo React Form Editor to update that form definition.

Example: Initial Value Example

akvo-react-form antd

Custom Params

Custom parameters are key-value pairs that we can implement in the Webform Editor.

Example:

<WebformEditor
  customParams={{
    label: 'Set Custom Parameter',
    params: [
      {
        name: 'params_name_a',
        label: 'Single Option Param',
        type: 'option',
        multiple: false,
        options: [
          { label: 'Option 1', value: 'SO1' },
          { label: 'Option 2', value: 'SO2' },
        ],
      },
      {
        name: 'params_name_b',
        label: 'Multiple Option Param',
        type: 'option',
        multiple: true,
        options: [
          { label: 'Multiple Option 1', value: 'MO1' },
          { label: 'Multiple Option 2', value: 'MO2' },
        ],
      },
      {
        name: 'params_name_c',
        label: 'Input Param',
        type: 'input',
      },
    ],
  }}
/>

Custom Parameters Setting

PropsDescriptionType
labelLabel for the custom params tabString | undefined
paramsList of custom parametersArray[Custom Parameters]

Custom Parameters

PropsDescriptionType
nameParameter nameString
labelParameter labelString | undefined
typeField Typeoption | input | number
multipleWhether multiple or notBoolean
optionsParameter OptionsArray[Option Parameters] | undefined

Option Parameters

PropsDescriptionType
labelLabel for the params optionsString | undefined
valueValue for the params optionsString

License

AGPL-3.0 © akvo

1.1.8

5 months ago

1.1.7

8 months ago

1.1.6

8 months ago

1.1.5

8 months ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1-2

2 years ago

1.0.1-1

2 years ago

1.0.1-0

2 years ago