diff --git a/intervention/forms.py b/intervention/forms.py index 540e21d3..626c095c 100644 --- a/intervention/forms.py +++ b/intervention/forms.py @@ -175,6 +175,9 @@ class NewInterventionForm(BaseForm): ) ) + # Define w-100 for all form fields + full_width_fields = True + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.form_title = _("New intervention") diff --git a/konova/forms.py b/konova/forms.py index 4575ee88..e33afa50 100644 --- a/konova/forms.py +++ b/konova/forms.py @@ -43,6 +43,7 @@ class BaseForm(forms.Form): instance = None # The data holding model object form_attrs = {} # Holds additional attributes, that can be used in the template has_required_fields = False # Automatically set. Triggers hint rendering in templates + full_width_fields = False # w-100 for all input fields def __init__(self, *args, **kwargs): self.instance = kwargs.pop("instance", None) @@ -55,6 +56,11 @@ class BaseForm(forms.Form): self.has_required_fields = True break + if self.full_width_fields: + # Automatically add bootstrap w-100 class for maximum width of form fields in modals + for key, val in self.fields.items(): + self.add_widget_html_class(key, "w-100") + @abstractmethod def save(self): # To be implemented in subclasses! @@ -185,15 +191,10 @@ class BaseModalForm(BaseForm, BSModalForm): """ is_modal_form = True render_submit = True - full_width_fields = False template = "modal/modal_form.html" def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - if self.full_width_fields: - # Automatically add bootstrap w-100 class for maximum width of form fields in modals - for key, val in self.fields.items(): - self.add_widget_html_class(key, "w-100") def process_request(self, request: HttpRequest, msg_success: str = _("Object removed"), msg_error: str = FORM_INVALID, redirect_url: str = None): """ Generic processing of request