mburst/django-threaded-comments-tutorial

Appended form retains input value of the original

Closed this issue · 2 comments

As per the title, when the form is appended, the input value from the original is also appended, so instead of giving a new clean form, I get a form with the original's input value. Basically:

  1. empty form
  2. click submit --> even is triggered
  3. form content is posted, as desired
  4. content from original is cloned(when the clone() is called) to children, instead of giving a clean form

If you still manage the project, I'd really appreciate the help!

https://github.com/mburst/django-threaded-comments-tutorial/blob/master/core/views.py#L6 is the line you're looking for. The form gets populated with post data after the first submit. To solve this you could instantiate the form with post data inside the if statement. Then add an else statement to instantiate a blank form. Let me know if this solves the issue for you.

EDIT: I think i misinterpreted what you asked. https://github.com/mburst/django-threaded-comments-tutorial/blob/master/comments_tutorial/templates/index.html#L13 is probably the line you're looking for. You can just say something like form.find('textarea').val('')

I played around with the jQuery and was on the verge of head slamming onto the desk, then I realized I missed the "return redirect("path.to.home.view") line in views.py which solved the issue of the input value being cloned to children forms, and felt like a moron, then shortly after rejoiced. Your code is working perfectly, I was just inattentive.