Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crispy Forms submits with no save and 302 #186

Open
ggyczew opened this issue Sep 18, 2021 · 0 comments
Open

Crispy Forms submits with no save and 302 #186

ggyczew opened this issue Sep 18, 2021 · 0 comments
Labels
Q&A Questions and answers

Comments

@ggyczew
Copy link

ggyczew commented Sep 18, 2021

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'
          )
      )

`

@trco trco added the Q&A Questions and answers label Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Q&A Questions and answers
Projects
None yet
Development

No branches or pull requests

2 participants