jonseager
jonseager

Reputation: 317

Populating Django form after AJAX request

I've got a django app in progress that is based loosely on the books example in the django book. There is a database of books which I have displayed in a table, when you click on the book it takes you to "/editbook/bookname" where it displays a ModelForm.

I'd like to move over to displaying the form in a modal dialog over the table - meaning the modal dialog code is already in place on the template like so (simplified!)

<div id="modal">
    {{form.as_table}}
</div>

The page loads and then an AJAX request is made to "/editbook/bookname" when the user selects a book; obviously the form won't display as the page is already rendered when the request is made - how can I update the page suitably so the form actually renders once the request has been made?

Thanks

Upvotes: 0

Views: 395

Answers (1)

Brandon Taylor
Brandon Taylor

Reputation: 34553

Most modal window implementations like jqModal, jQueryUI, Fancybox, etc, allow you to load content into the modal in an iFrame.

You could just create a view that contains your form that you load into the iFrame in the modal and go from there. It's a pattern I've used many times on several Django projects.

Upvotes: 1

Related Questions