diff --git a/src/InSillyCloWeb/assemblies/forms.py b/src/InSillyCloWeb/assemblies/forms.py index f948f608ef380e17ed5abde61dc4e8f83a940e91..5bc05af205b1c7f6812976f568c49a789b9f2f2a 100644 --- a/src/InSillyCloWeb/assemblies/forms.py +++ b/src/InSillyCloWeb/assemblies/forms.py @@ -214,11 +214,17 @@ class InputPartForm(forms.ModelForm): css_class='num-sub-parts-str', ), ) + self.fields['nb_subpart_allowed'].label = mark_safe(self.fields['nb_subpart_allowed'].label + asterisk) - # def clean(self): - # cleaned_data = super().clean() - # cleaned_data['assembly'] = self.assembly - # return cleaned_data + def clean(self): + cleaned_data = super().clean() + if self.errors: + return cleaned_data + if cleaned_data["is_typed"] and not cleaned_data["is_separable"]: + cleaned_data["number_of_subparts_str"] = f"[1]" + if len(cleaned_data["nb_subpart_allowed"]) == 0 and cleaned_data["is_separable"] and cleaned_data["is_typed"]: + self.add_error('nb_subpart_allowed', _('You have to specify at least one configuration')) + return cleaned_data InputPartFormFormSet = formset_factory(