Skip to content

Crispy Forms submits with no save and 302 #186

Open
@ggyczew

Description

@ggyczew

I had an issue submitting From generated with Crispy Forms.
I have got no save of forma data and 302 response. Modal window did not close.

What I found is that Crispy Form's Layuot elements Submit, Button do not work. They render .
But if replaced with from your example then the form works as expected.

Bellow is a form class with three button options i have tested.
First two render html code as in the examples on the right.

`

class BookModelForm(BSModalModelForm):
  publication_date = forms.DateField(
      error_messages={'invalid': 'Enter a valid date in YYYY-MM-DD format.'}
  )
  class Meta:
      model = Book
      exclude = ['timestamp']

  def __init__(self, *args, **kwargs):
      super(BookModelForm, self).__init__(*args, **kwargs)
      self.helper = FormHelper()
      self.helper.form_tag = True
      self.helper.layout = Layout(
          Div(HTML('''<h3>Create Book</h3> 
                          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                              <span aria-hidden="true">&times;</span>
                          </button>'''), 
                  css_class='modal-header'
          ),
          Div(Field('title', 'publication_date', 'author', 'price', 'pages', 'book_type'), css_class='modal-body'),
          Div(
              # Button('submit', 'Create'), #<input type="button" name="submit" value="Create" class="btn" id="button-id-submit">
              # Submit('submit', 'Create'), #<input type="submit" name="submit" value="Create" class="btn btn-primary" id="submit-id-submit">
              HTML('<button type="submit" class="btn btn-primary">Create</button>'),
              css_class='modal-footer'
          )
      )

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Q&AQuestions and answers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions