Skip to content

Commit a5a84a3

Browse files
committed
fix: handle BE response
1 parent 9461133 commit a5a84a3

File tree

2 files changed

+11
-6
lines changed
  • locales/it/LC_MESSAGES
  • src/customizations/volto-form-block/components

2 files changed

+11
-6
lines changed

locales/it/LC_MESSAGES/volto.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2442,7 +2442,7 @@ msgstr "A volte non capivo se stavo procedendo correttamente"
24422442
#: overrideTranslations
24432443
# defaultMessage: Check this box if the value entered in this field can be used only once.
24442444
msgid "field_unique_description"
2445-
msgstr "Seleziona questo checkbox se il valore inserito in questo campo può essere utilizzato solo una volta"
2445+
msgstr "Richiedi un valore univoco: il valore inserito dagli utenti in questo campo non può essere già stato utilizzato in altre compilazioni del form."
24462446

24472447
#: overrideTranslations
24482448
# defaultMessage: Unique field

src/customizations/volto-form-block/components/View.jsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// CUSTOMIZATION:
22
// - added warning state to form
33
// - backport for https://github.com/collective/volto-form-block/pull/122
4-
4+
// - handle field errors coming from backend
55
import React, { useState, useEffect, useReducer, useRef } from 'react';
66
import { useSelector, useDispatch } from 'react-redux';
77
import PropTypes from 'prop-types';
@@ -141,7 +141,6 @@ const View = ({ data, id, path }) => {
141141

142142
const [formState, setFormState] = useReducer(formStateReducer, initialState);
143143
const [formErrors, setFormErrors] = useState([]);
144-
console.log(formErrors);
145144

146145
const submitResults = useSelector(
147146
(state) => state.submitForm?.subrequests?.[id],
@@ -360,9 +359,15 @@ const View = ({ data, id, path }) => {
360359
let errorDescription = `${
361360
JSON.parse(submitResults.error.response?.text ?? '{}')?.message
362361
}`;
363-
const fieldsErrors = JSON.parse(
364-
submitResults.error.response?.text ?? '{}',
365-
)?.fields_errors;
362+
363+
//CUSTOM: handle field errors coming from backend
364+
365+
let fieldsErrors = [];
366+
if (errorDescription.startsWith('[')) {
367+
fieldsErrors = JSON.parse(
368+
errorDescription.replaceAll('"', '\\"').replaceAll("'", '"'),
369+
);
370+
}
366371

367372
// fieldsErrors = [
368373
// { field_id: '1767088715579', label: 'univoco', message: 'Errore' },

0 commit comments

Comments
 (0)