Full width fields
* refactors full width fields from BaseModalForm into BaseForm to have this nice little feature for regular forms as well!
This commit is contained in:
parent
8b1223e780
commit
72ed82ecd6
@ -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")
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user