Skip to content

collective/volto-form-block

Folders and files

NameName
Last commit message
Last commit date
Mar 20, 2021
Jul 7, 2022
Aug 2, 2022
Aug 19, 2021
Jul 5, 2021
May 13, 2021
Jul 7, 2022
Aug 7, 2021
Jan 4, 2022
Nov 25, 2021
May 13, 2021
Jul 7, 2022
Nov 25, 2021

Repository files navigation

volto-form-block

Volto addon which adds a customizable form using a block. Intended to be used with collective.volto.formsupport.

Install with mrs-developer (see Volto docs) or with:

yarn add volto-form-block

Note: Since version v2.0.0 of this addon, it's required collective.volto.formsupport 2.0.0 or higher (and its upgrade steps).

Note: Since version v2.1.2 of this addon, it's required Volto 14.2.0

Features

This addon will add in your project the Form block and the needed reducers.

Form block in chooser

Form block view

Using the engine of subblocks, you can manage form fields adding, sorting and deleting items.

For each field, you can select the field type from:

  • Text
  • Textarea
  • Select
  • Single choice (radio buttons)
  • Multiple choice (checkbox buttons)
  • Checkbox
  • Date picker
  • File upload with DnD
  • E-mail
  • Static rich text (not a fillable field, just text to display between other fields)

For every field you can set a label and a help text. For select, radio and checkbox fields, you can select a list of values.

Captcha verification

This form addon is configured to work with HCaptcha and ReCaptcha to prevent spam. In order to make one of these integrations work, you need to add an enviroment variable with the key RAZZLE_HCAPTCHA_KEY or RAZZLE_RECAPTCHA_KEY and the value of the key in your .env file.

HCaptcha

With HCaptcha integration, you also get an additional option in the sidebar to enable or disable the invisible captcha (see implications here).

Export

With backend support, you can store data submitted from the form. In Edit, you can export and clear stored data from the sidebar.

Form export

Additional fields

In addition to the fields described above, you can add any field you want. If you need a field that is not supported, PRs are always welcome, but if you have to use a custom field tailored on your project needs, then you can add additional custom fields.

config.blocks.blocksConfig.form.additionalFields.push({
  id: 'field type id',
  label:
    intl.formatMessage(messages.customFieldLabel) ||
    'Label for field type select, translation obj or string',
  component: MyCustomWidget,
  isValid: (formData, name) => true,
});

The widget component should have the following firm:

({
  id,
  name,
  title,
  description,
  required,
  onChange,
  value,
  isDisabled,
  invalid,
}) => ReactElement;

You should also pass a function to validate your field's data. The isValid function accepts formData (the whole form data) and the name of the field, thus you can access to your fields' data as formData[name] but you also have access to other fields.

isValid has the firm:

(formData, name) => boolean;

Example custom field here.

Static fields

In backend integration, you can add in block data an object called static_fields and the form block will show those in form view as readonly and will aggregate those with user compiled data.

i.e.: aggregated data from user federated authentication:

Static fields

Video demos