Skip to content

Form

Definition

A form component contains all the templates for creating and managing forms. Forms are used to collect user input and submit data.

Forms can include various fields, which can be organized into a directory to improve readability.

  • Contains all form templates.
  • Fields:
  • Optional directory for better organization and readability.
  • Includes all the necessary fields for the form.

Example

<div class="fs-6 mb-2">We unfortunately can't glue a model in the view here. Here's what the code would look like if we could!</div>
<div class="fs-5">Create Recipe Form</div>
<form
    class="row"
    x-data="{
        recipe: new ModelObjectGlue('recipe'),
        async init() {
            await this.recipe.get()
        }
    }"
>
    {% csrf_token %}
    <div class="col-6 py-1">
        {% include 'django_glue/form/field/char_field.html' with glue_field='name' %}
    </div>
    <div class="col-6 py-1">
        {% include 'django_glue/form/field/select_field.html' with glue_field='course' %}
    </div>
    <div class="col-12 py-1">
        {% include 'django_glue/form/field/text_field.html' with glue_field='description' %}
    </div>
    <div class="col-6 py-1">
        {% include 'django_glue/form/field/number_field.html' with glue_field='prep_time' %}
    </div>
    <div class="col-6 py-1">
        {% include 'django_glue/form/field/number_field.html' with glue_field='servings' %}
    </div>
    {% include 'django_spire/contrib/form/button/form_submit_button.html' %}
</form>