forked from italia/design-comuni-plone-theme
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add pluggable custom validation for all datagrid fields, not jus…
…t required ones and applied new validation to timeline_tempi_scadenze (#357) * fix: add pluggable custom validation for all datagrid fields, not just required ones and applied new validation to timeline_tempi_scadenze * fix: validation check for timeline_tempi_scadenze * fix: customizations doc comment example
- Loading branch information
1 parent
b3ec883
commit 9c6f55c
Showing
9 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Plone\n" | ||
"POT-Creation-Date: 2023-09-20T11:30:56.175Z\n" | ||
"POT-Creation-Date: 2023-10-10T15:52:06.253Z\n" | ||
"Last-Translator: Plone i18n <[email protected]>\n" | ||
"Language-Team: Plone i18n <[email protected]>\n" | ||
"MIME-Version: 1.0\n" | ||
|
@@ -3735,6 +3735,11 @@ msgstr "" | |
msgid "text_filter_placeholder" | ||
msgstr "" | ||
|
||
#: helpers/FormValidation/DataGridFormValidationHelpers | ||
# defaultMessage: Impossibile aggiungere un elemento alla timeline senza aver compilato il campo "Titolo" | ||
msgid "timeline_tempi_scadenze_validation_error" | ||
msgstr "" | ||
|
||
#: components/ItaliaTheme/View/BandoView/BandoText | ||
# defaultMessage: Tipologia del bando | ||
msgid "tipologia_bando" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/helpers/FormValidation/DataGridFormValidationHelpers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { defineMessages } from 'react-intl'; | ||
|
||
const dgfieldValidationMessages = defineMessages({ | ||
timeline_tempi_scadenze_validation_error: { | ||
id: 'timeline_tempi_scadenze_validation_error', | ||
defaultMessage: | ||
'Impossibile aggiungere un elemento alla timeline senza aver compilato il campo "Titolo"', | ||
}, | ||
}); | ||
|
||
export const CUSTOM_DGFIELD_VALIDATION = { | ||
timeline_tempi_scadenze: { | ||
isValid: (value, itemObj, intlFunc) => { | ||
const isValid = value.every((val, i) => val.title); | ||
return !isValid | ||
? intlFunc( | ||
dgfieldValidationMessages.timeline_tempi_scadenze_validation_error, | ||
) | ||
: null; | ||
}, | ||
}, | ||
}; | ||
|
||
// Obbligati a far cosi' perche' il backend non è abbastanza furbo da definire | ||
// una specifica factory non innestata o field.widget ofield.type per dgf e | ||
// invece fornisce solo un generico "List" o "array", che avrebbe | ||
// un'altra validazione in Volto. | ||
export const realWidgetType = (field, fieldId) => { | ||
return field?.widgetOptions?.frontendOptions?.widget === 'data_grid' | ||
? fieldId | ||
: field.widget || field.type; | ||
}; | ||
|
||
export const getSpecificDataGridFieldValidation = (fieldId) => { | ||
return fieldId && CUSTOM_DGFIELD_VALIDATION.hasOwnProperty(fieldId) | ||
? Object.keys(CUSTOM_DGFIELD_VALIDATION[fieldId]) | ||
: []; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters