From 2eacf1471727fe97830a90b69f93e8211b6964e5 Mon Sep 17 00:00:00 2001 From: monodo Date: Tue, 28 May 2024 15:31:05 +0200 Subject: [PATCH] set validation for geom field (#1005) --- geocity/apps/forms/admin.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/geocity/apps/forms/admin.py b/geocity/apps/forms/admin.py index fbd9e4bca..d7396111b 100644 --- a/geocity/apps/forms/admin.py +++ b/geocity/apps/forms/admin.py @@ -556,6 +556,22 @@ def clean_maximum_date(self): return maximum_date + def clean_map_widget_configuration(self): + selected_input_type = self.cleaned_data.get("input_type") + map_widget_configuration = self.cleaned_data.get("map_widget_configuration") + + if ( + selected_input_type == models.Field.INPUT_TYPE_GEOM + and not map_widget_configuration + ): + raise forms.ValidationError( + _( + "Vous devez obligatoirement sélectionner une configuration de carte avancée." + ) + ) + + return map_widget_configuration + class Media: js = ("js/admin/form_field.js",)