From 29cacb115c499654a7e79343a971ccd4fc5a0e48 Mon Sep 17 00:00:00 2001 From: Nicola Zambello Date: Tue, 3 Aug 2021 09:34:43 +0200 Subject: [PATCH] feat: additionalFields from config --- README.md | 15 ++++++++ locales/de/LC_MESSAGES/volto.po | 8 +++++ locales/en/LC_MESSAGES/volto.po | 8 +++++ locales/es/LC_MESSAGES/volto.po | 8 +++++ locales/eu/LC_MESSAGES/volto.po | 8 +++++ locales/fr/LC_MESSAGES/volto.po | 8 +++++ locales/it/LC_MESSAGES/volto.po | 8 +++++ locales/ja/LC_MESSAGES/volto.po | 8 +++++ locales/nl/LC_MESSAGES/volto.po | 8 +++++ locales/pt/LC_MESSAGES/volto.po | 8 +++++ locales/pt_BR/LC_MESSAGES/volto.po | 58 +++++++----------------------- locales/ro/LC_MESSAGES/volto.po | 8 +++++ locales/volto.pot | 12 ++++++- src/components/Field.jsx | 22 ++++++++++++ src/components/Sidebar.jsx | 5 +++ src/index.js | 1 + 16 files changed, 147 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 8de2564..5feabcd 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,21 @@ 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. + +```jsx +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, +}); +``` + ## 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. diff --git a/locales/de/LC_MESSAGES/volto.po b/locales/de/LC_MESSAGES/volto.po index 70ccb92..01a9d6d 100644 --- a/locales/de/LC_MESSAGES/volto.po +++ b/locales/de/LC_MESSAGES/volto.po @@ -27,6 +27,10 @@ msgstr "" msgid "Form" msgstr "" +#: components/Sidebar +msgid "description" +msgstr "" + #: components/Form msgid "formSubmitted" msgstr "" @@ -175,3 +179,7 @@ msgstr "" #: components/Sidebar msgid "form_useAsReplyTo_description" msgstr "" + +#: components/Sidebar +msgid "title" +msgstr "" diff --git a/locales/en/LC_MESSAGES/volto.po b/locales/en/LC_MESSAGES/volto.po index 13f17eb..a18c80a 100644 --- a/locales/en/LC_MESSAGES/volto.po +++ b/locales/en/LC_MESSAGES/volto.po @@ -27,6 +27,10 @@ msgstr "Errore" msgid "Form" msgstr "Form" +#: components/Sidebar +msgid "description" +msgstr "" + #: components/Form msgid "formSubmitted" msgstr "Form successfully submitted" @@ -175,3 +179,7 @@ msgstr "Use as 'reply to'" #: components/Sidebar msgid "form_useAsReplyTo_description" msgstr "If selected, this will be the address the receiver can use to reply." + +#: components/Sidebar +msgid "title" +msgstr "" diff --git a/locales/es/LC_MESSAGES/volto.po b/locales/es/LC_MESSAGES/volto.po index 70ccb92..01a9d6d 100644 --- a/locales/es/LC_MESSAGES/volto.po +++ b/locales/es/LC_MESSAGES/volto.po @@ -27,6 +27,10 @@ msgstr "" msgid "Form" msgstr "" +#: components/Sidebar +msgid "description" +msgstr "" + #: components/Form msgid "formSubmitted" msgstr "" @@ -175,3 +179,7 @@ msgstr "" #: components/Sidebar msgid "form_useAsReplyTo_description" msgstr "" + +#: components/Sidebar +msgid "title" +msgstr "" diff --git a/locales/eu/LC_MESSAGES/volto.po b/locales/eu/LC_MESSAGES/volto.po index 70ccb92..01a9d6d 100644 --- a/locales/eu/LC_MESSAGES/volto.po +++ b/locales/eu/LC_MESSAGES/volto.po @@ -27,6 +27,10 @@ msgstr "" msgid "Form" msgstr "" +#: components/Sidebar +msgid "description" +msgstr "" + #: components/Form msgid "formSubmitted" msgstr "" @@ -175,3 +179,7 @@ msgstr "" #: components/Sidebar msgid "form_useAsReplyTo_description" msgstr "" + +#: components/Sidebar +msgid "title" +msgstr "" diff --git a/locales/fr/LC_MESSAGES/volto.po b/locales/fr/LC_MESSAGES/volto.po index 92120a9..59ed230 100644 --- a/locales/fr/LC_MESSAGES/volto.po +++ b/locales/fr/LC_MESSAGES/volto.po @@ -27,6 +27,10 @@ msgstr "Erreur" msgid "Form" msgstr "Formulaire" +#: components/Sidebar +msgid "description" +msgstr "" + #: components/Form msgid "formSubmitted" msgstr "Formulaire soumis avec succès" @@ -175,3 +179,7 @@ msgstr "" #: components/Sidebar msgid "form_useAsReplyTo_description" msgstr "" + +#: components/Sidebar +msgid "title" +msgstr "" diff --git a/locales/it/LC_MESSAGES/volto.po b/locales/it/LC_MESSAGES/volto.po index 5935f8b..f447f76 100644 --- a/locales/it/LC_MESSAGES/volto.po +++ b/locales/it/LC_MESSAGES/volto.po @@ -27,6 +27,10 @@ msgstr "Errore" msgid "Form" msgstr "Form" +#: components/Sidebar +msgid "description" +msgstr "" + #: components/Form msgid "formSubmitted" msgstr "Form invato correttamente" @@ -175,3 +179,7 @@ msgstr "Usa come 'reply to'" #: components/Sidebar msgid "form_useAsReplyTo_description" msgstr "Se selezionato, questo sarà l'indirizzo a cui il destinatario potrà rispondere." + +#: components/Sidebar +msgid "title" +msgstr "" diff --git a/locales/ja/LC_MESSAGES/volto.po b/locales/ja/LC_MESSAGES/volto.po index 70ccb92..01a9d6d 100644 --- a/locales/ja/LC_MESSAGES/volto.po +++ b/locales/ja/LC_MESSAGES/volto.po @@ -27,6 +27,10 @@ msgstr "" msgid "Form" msgstr "" +#: components/Sidebar +msgid "description" +msgstr "" + #: components/Form msgid "formSubmitted" msgstr "" @@ -175,3 +179,7 @@ msgstr "" #: components/Sidebar msgid "form_useAsReplyTo_description" msgstr "" + +#: components/Sidebar +msgid "title" +msgstr "" diff --git a/locales/nl/LC_MESSAGES/volto.po b/locales/nl/LC_MESSAGES/volto.po index 70ccb92..01a9d6d 100644 --- a/locales/nl/LC_MESSAGES/volto.po +++ b/locales/nl/LC_MESSAGES/volto.po @@ -27,6 +27,10 @@ msgstr "" msgid "Form" msgstr "" +#: components/Sidebar +msgid "description" +msgstr "" + #: components/Form msgid "formSubmitted" msgstr "" @@ -175,3 +179,7 @@ msgstr "" #: components/Sidebar msgid "form_useAsReplyTo_description" msgstr "" + +#: components/Sidebar +msgid "title" +msgstr "" diff --git a/locales/pt/LC_MESSAGES/volto.po b/locales/pt/LC_MESSAGES/volto.po index 70ccb92..01a9d6d 100644 --- a/locales/pt/LC_MESSAGES/volto.po +++ b/locales/pt/LC_MESSAGES/volto.po @@ -27,6 +27,10 @@ msgstr "" msgid "Form" msgstr "" +#: components/Sidebar +msgid "description" +msgstr "" + #: components/Form msgid "formSubmitted" msgstr "" @@ -175,3 +179,7 @@ msgstr "" #: components/Sidebar msgid "form_useAsReplyTo_description" msgstr "" + +#: components/Sidebar +msgid "title" +msgstr "" diff --git a/locales/pt_BR/LC_MESSAGES/volto.po b/locales/pt_BR/LC_MESSAGES/volto.po index fd7b4b6..795972d 100644 --- a/locales/pt_BR/LC_MESSAGES/volto.po +++ b/locales/pt_BR/LC_MESSAGES/volto.po @@ -17,207 +17,175 @@ msgstr "" "Domain: volto\n" "X-Generator: Poedit 2.4.3\n" -# defaultMessage: Aggiungi un campo -#: components/Edit + #: components/Edit msgid "Add field" msgstr "Adicionar campo" -# defaultMessage: Cancel #: components/Sidebar msgid "Cancel" msgstr "Cancelar" -# defaultMessage: Error #: components/FormView msgid "Error" msgstr "Erro" -# defaultMessage: Form #: components/Sidebar msgid "Form" msgstr "Formulário" -# defaultMessage: Form successfully submitted +#: components/Sidebar +msgid "description" +msgstr "" + #: components/Form msgid "formSubmitted" msgstr " Formulário enviado com sucesso" -# defaultMessage: Attached file will be sent via email, but not stored #: components/Sidebar msgid "form_attachment_info_text" msgstr "O arquivo anexado será enviado por e-mail, mas não armazenado" -# defaultMessage: Clear data #: components/Sidebar msgid "form_clear_data" msgstr "Limpar dados" -# defaultMessage: Are you sure you want to delete all saved items? #: components/Sidebar msgid "form_confirmClearData" msgstr "Você tem certeza que deseja apagar todos as respostas salvas?" -# defaultMessage: Default sender #: components/Sidebar msgid "form_default_from" msgstr "Remetente padrão" -# defaultMessage: This address will be used as the sender of the email with the form data #: components/Sidebar msgid "form_default_from_description" msgstr "Este endereço será utilizado como o remetente do e-mail com os dados do formulário" -# defaultMessage: Mail subject #: components/Sidebar msgid "form_default_subject" msgstr "Assunto do e-mail" -# defaultMessage: Invia -#: components/Edit components/FormView +#: components/Edit +#: components/FormView msgid "form_default_submit_label" msgstr "Enviar" -# defaultMessage: Export data #: components/Sidebar msgid "form_edit_exportCsv" msgstr "Exportar dados" -# defaultMessage: Attenzione! #: components/Edit msgid "form_edit_warning" msgstr "Atenção" -# defaultMessage: Enter a field of type 'Sender E-mail'. If it is not present, or it is present but not filled in by the user, the sender address of the e-mail will be the one configured in the right sidebar. #: components/Edit msgid "form_edit_warning_from" msgstr "Digite um campo do tipo 'E-mail do remetente'. Se não estiver presente, ou estiver presente mas não for preenchido pelo usuário, o endereço do remetente do e-mail será o configurado na barra lateral direita." -# defaultMessage: Fill in the required fields #: components/FormView msgid "form_empty_values_validation" msgstr "Por favor preencha os campos obrigatórios" -# defaultMessage: Description #: components/Sidebar msgid "form_field_description" msgstr "Descrição" -# defaultMessage: Possible values #: components/Sidebar msgid "form_field_input_values" msgstr "Valores possíveis" -# defaultMessage: Label #: components/Sidebar msgid "form_field_label" msgstr "Etiqueta" -# defaultMessage: Name #: components/Sidebar msgid "form_field_name" msgstr "Nome" -# defaultMessage: The name must contain spaces, and can only contain alphanumeric characters in addition to the "-" and "_" characters. The name is the same as the name of the parameter. #: components/Sidebar msgid "form_field_name_description" -msgstr "O nome deve conter espaços e só pode conter caracteres alfanuméricos além dos caracteres \"-\" e \"_\". O nome é igual ao nome do parâmetro." +msgstr "O nome deve conter espaços e só pode conter caracteres alfanuméricos além dos caracteres "-" e "_". O nome é igual ao nome do parâmetro." -# defaultMessage: Required #: components/Sidebar msgid "form_field_required" msgstr "Obrigatório" -# defaultMessage: Field type #: components/Sidebar msgid "form_field_type" msgstr "Tipo de campo" -# defaultMessage: Attachment #: components/Sidebar msgid "form_field_type_attachment" msgstr "Anexo" -# defaultMessage: Multiple choice #: components/Sidebar msgid "form_field_type_checkbox" msgstr "Múltipla escolha" -# defaultMessage: Date #: components/Sidebar msgid "form_field_type_date" msgstr "Data" -# defaultMessage: E-mail #: components/Sidebar msgid "form_field_type_from" msgstr "E-mail" -# defaultMessage: Single choice #: components/Sidebar msgid "form_field_type_radio" msgstr "Escolha única" -# defaultMessage: List #: components/Sidebar msgid "form_field_type_select" msgstr "Opções" -# defaultMessage: Text #: components/Sidebar msgid "form_field_type_text" msgstr "Texto" -# defaultMessage: Textarea #: components/Sidebar msgid "form_field_type_textarea" msgstr "Área de texto" -# defaultMessage: {formDataCount} item(s) stored #: components/Sidebar msgid "form_formDataCount" msgstr "{formDataCount} item(ns) armazenados" -# defaultMessage: Clear #: components/FormView msgid "form_reset" msgstr "Limpar" -# defaultMessage: Store compiled data #: components/Sidebar msgid "form_save_persistent_data" msgstr "Armazenar dados" -# defaultMessage: Seleziona un valore #: components/Field msgid "form_select_a_value" msgstr "Selecione um valor" -# defaultMessage: Send email to recipient #: components/Sidebar msgid "form_send_email" msgstr "Enviar e-mail para o destinatário" -# defaultMessage: Submit button label #: components/Sidebar msgid "form_submit_label" msgstr "Texto do botão de enviar" -# defaultMessage: Sent! #: components/FormView msgid "form_submit_success" msgstr "Enviado!" -# defaultMessage: Recipients #: components/Sidebar msgid "form_to" msgstr "Destinatários" -# defaultMessage: undefined #: components/Sidebar msgid "form_useAsReplyTo" msgstr "Utilizar como 'responder para'" -# defaultMessage: undefined #: components/Sidebar msgid "form_useAsReplyTo_description" -msgstr "Usar este campo como valor do cabeçalho de \"responder para\"" +msgstr "Usar este campo como valor do cabeçalho de "responder para"" + +#: components/Sidebar +msgid "title" +msgstr "" diff --git a/locales/ro/LC_MESSAGES/volto.po b/locales/ro/LC_MESSAGES/volto.po index 70ccb92..01a9d6d 100644 --- a/locales/ro/LC_MESSAGES/volto.po +++ b/locales/ro/LC_MESSAGES/volto.po @@ -27,6 +27,10 @@ msgstr "" msgid "Form" msgstr "" +#: components/Sidebar +msgid "description" +msgstr "" + #: components/Form msgid "formSubmitted" msgstr "" @@ -175,3 +179,7 @@ msgstr "" #: components/Sidebar msgid "form_useAsReplyTo_description" msgstr "" + +#: components/Sidebar +msgid "title" +msgstr "" diff --git a/locales/volto.pot b/locales/volto.pot index ce623fd..b65a64f 100644 --- a/locales/volto.pot +++ b/locales/volto.pot @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: Plone\n" - "POT-Creation-Date: 2021-04-07T13:07:21.178Z\n" + "POT-Creation-Date: 2021-08-03T07:34:46.833Z\n" "Last-Translator: Plone i18n \n" "Language-Team: Plone i18n \n" "MIME-Version: 1.0\n" @@ -33,6 +33,11 @@ msgstr "" msgid "Form" msgstr "" +#: components/Sidebar +# defaultMessage: Description +msgid "description" +msgstr "" + #: components/Form # defaultMessage: Form successfully submitted msgid "formSubmitted" @@ -218,3 +223,8 @@ msgstr "" # defaultMessage: undefined msgid "form_useAsReplyTo_description" msgstr "" + +#: components/Sidebar +# defaultMessage: Title +msgid "title" +msgstr "" diff --git a/src/components/Field.jsx b/src/components/Field.jsx index 845cade..1260148 100644 --- a/src/components/Field.jsx +++ b/src/components/Field.jsx @@ -13,6 +13,8 @@ import RadioWidget from './Widget/RadioWidget'; import './Field.css'; +import config from '@plone/volto/registry'; + const messages = defineMessages({ select_a_value: { id: 'form_select_a_value', @@ -172,6 +174,26 @@ const Field = ({ {...(isInvalid() ? { className: 'is-invalid' } : {})} /> )} + {config.blocks.blocksConfig.form.additionalFields?.reduce((acc, val) => { + if (val.id === field_type) + return [ + ...acc, + , + ]; + + return acc; + }, []) ?? []} ); }; diff --git a/src/components/Sidebar.jsx b/src/components/Sidebar.jsx index ad3a570..4428b7e 100644 --- a/src/components/Sidebar.jsx +++ b/src/components/Sidebar.jsx @@ -30,6 +30,8 @@ import deleteSVG from '@plone/volto/icons/delete.svg'; import { getFormData, exportCsvFormData, clearFormData } from '../actions'; +import config from '@plone/volto/registry'; + const messages = defineMessages({ title: { id: 'title', @@ -466,6 +468,9 @@ const Sidebar = ({ intl.formatMessage(messages.field_type_attachment), ], ['from', intl.formatMessage(messages.field_type_from)], + ...(config.blocks.blocksConfig.form.additionalFields?.map( + (fieldType) => [fieldType.id, fieldType.label], + ) ?? []), ]} /> diff --git a/src/index.js b/src/index.js index 0d4f2c9..dfa6601 100644 --- a/src/index.js +++ b/src/index.js @@ -24,6 +24,7 @@ const applyConfig = (config) => { group: 'text', view: View, edit: Edit, + additionalFields: [], restricted: false, mostUsed: true, security: {