How do I insert a django form in twitter-bootstrap modal window?

后端 未结 2 1557
余生分开走
余生分开走 2020-11-27 11:02

Someone has asked the exact same question in April, without any answer. But since he provided too little information; the question was abandoned.

I have the same pro

2条回答
  •  再見小時候
    2020-11-27 11:57

    I was having the same problem when I encounter this post. I tried this solution but it wasn't really working for me (but it gave me direction). I came up with a solution that does work for me but, it feels hacky and I would like to receive some pointers on how to do it better.

    The problem is the same: Show a form inside twitter boostrap modal and django form (edit/add model for me using django generic form views)

    So what I did:

    main.html

    
    
    
    
    Title
    
    

    editor.html

    So the flow is this:

    • click on the tag loads the form from the create form url into the modal div
    • click the save button in modal (submit) which triggers the genericLoadDialog function. This loads makes a POST request to the create form url with data collected from the form
    • If the form is invalid it reloads the modal html and shows the error fields, else closes the modal and django should save/redirect (I use get_success_url method in django form view but not working for me for some reason. It does save the object)

    I'm uncomfortable with the way I check if the form is valid or not in genericLoadDialog, if someone has a better idea would be nice.

提交回复
热议问题