Form objects¶
There is some forms you can use to quickly and automatically create a Foundation layout for your forms. This is mostly for fast integration or prototyping because it will probably never totally fit to your design.
-
class
crispy_forms_foundation.forms.
FoundationForm
(*args, **kwargs)¶ Bases:
crispy_forms_foundation.forms.FoundationFormMixin
,django.forms.forms.Form
A Django form that inherit from
FoundationFormMixin
to automatically build a form layoutExample:
from django import forms from crispy_forms_foundation.forms import FoundationForm class YourForm(FoundationForm): title = "Testing" action = 'test' layout = Layout(Fieldset("Section", "my_field", "my_field_2")) switches = False attrs = {'data_abide': ""} title = forms.CharField(label='Title', required=True) slug = forms.CharField(label='Slug', required=False)
-
class
crispy_forms_foundation.forms.
FoundationFormMixin
¶ Bases:
object
Mixin to implement the layout helper that will automatically build a form layout
Generally, you will prefer to use
FoundationForm
orFoundationModelForm
instead.If you still want to directly use this mixin you’ll just have to execute
FoundationFormMixin.init_helper()
in your form init.Attributes
- title
- If set, defines the form’s title
- layout
- If set, override the default layout for the form
- error_title
- Defines the error title for non field errors
- form_id
- Defines the id of the form
- classes
- Defines the classes used on the form
- action
- Defines the action of the form.
reverse
will be called on the value. On failure the value will be assigned as is - method
- Defines the method used for the action
- attrs
- Defines the attributes of the form
- switches
- If True, will replace all fields checkboxes with switches
- submit
- Adds a submit button on the form. Can be set to a Submit object or a string which will be used as the value of the submit button
- title_templatestring
- Template string used to display form title (if any)
-
class
crispy_forms_foundation.forms.
FoundationModelForm
(*args, **kwargs)¶ Bases:
crispy_forms_foundation.forms.FoundationFormMixin
,django.forms.models.ModelForm
A Django Model form that inherit from
FoundationFormMixin
to automatically build a form layoutExample:
from crispy_forms_foundation.forms import FoundationModelForm class YourForm(FoundationModelForm): title = "Testing" action = 'test' layout = Layout(Fieldset("Section", "my_field", "my_field_2")) switches = False attrs = {'data_abide': ""} class Meta: model = MyModel fields = ['my_field', 'my_field_2', 'my_field_3']