I'm using Django-crispy-forms, and I want to be able to place the Submit button in a different place than right next to the bottom of the form.
Here is my form:
from django import forms
from django.core.urlresolvers import reverse
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout, Button, Fieldset, ButtonHolder, Submit
from gpsim.models import GPSimConfig
class AddNewGPSimConfigForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(AddNewGPSimConfigForm, self).__init__(*args, **kwargs)
self.initial['name'] = ''
self.helper = FormHelper()
self.helper.form_id = 'add-new-gpsim-config'
self.helper.form_method = 'post'
self.helper.form_action = reverse('gpsim:add_gpsim_config')
self.helper.layout = Layout(
Fieldset(
'',
'name',
'other fields...',
),
ButtonHolder(
Submit('submit', 'Create', css_class='btn-default')
)
)
class Meta:
model = GPSimConfig
The template, is a Bootstrap modal popup. The modal initially shows a form with a list of GPSimConfig items to choose from. When the user chooses an item, then a span is loaded with this form via Jquery.
At the bottom of the modal, there is a cancel button, and I want to put the submit button down at the bottom next to the cancel button, but when the crispy-form is generated, it puts the submit button right after the last field and closes the form.
Here is the template that is loaded into the modal's 'modal-content' div.
{% extends "gpsim/tmpl_gpsim_modal_base.html" %}
{% load staticfiles %}
{% block modal-title %}Add GPSim Config{% endblock %}
{% block modal-body-left %}
Copy GPSim config from<br><br>
{% if my_gpsim_configs %}
My GPSim Configs<br>
<select id="my_gpsim_config_id" name="gpsim_config" class="form-control" onChange="load_span_from_select_change('my_gpsim_config_id','/gpsim/gpsim-config/add/?copy-from-id=', 'add_gpsim_config_span');">
<option>select</option>
{% for gpsim_config in my_gpsim_configs %}
<option value="{{gpsim_config.id}}">{{gpsim_config.name}}</option>
{% endfor %}
{% endif %}
{% endblock %}
{% block modal-body-right %}
<span id="add_gpsim_config_span"></span>
{% endblock %}
{% block modal-submit-button %}
<div id="submit-div">
</div>
{% endblock %}
The span "add_gpsim_config_span" is where the form will get loaded via Jquery, and the Submit button gets placed there, along with the form closing tag. I would like to put the Submit in the "submit-div" div, instead.
Is there a way to do this?