django-bootstrap-modal-forms icon indicating copy to clipboard operation
django-bootstrap-modal-forms copied to clipboard

Dynamically definition of the formURL in the create button.

Open glauciobb opened this issue 1 year ago • 0 comments
trafficstars

Hello, I would like to create a modal form where the formURL is dynamically defined according to the selected row in a table.

I was able to load the form dynamically as follows.

$("#create-btn").on("click", function() {
        var formURL = get_url(); // Get the form URL based on the selected table row.
        $('#modal').find('.modal-content').load(formURL, function () {
            $('#modal').find('.modal-content form').attr("action", formURL);
            $('#modal').modal("show");
        });
    });

image

But this way, event handlers are not added, as they are when function modalForm is called, and when the form is submitted and any ValidationError is raised, the browser redirects to the modal's template as follow.

image

I understand that I have to add the event handlers on the modal for them to stay even after errors, but I don't know how to do it. So, is there any way I'm not seeing to dynamically define the formURL or add the events after loading the form? As I'm kind new to Django itself, there's a better way to achieve this behavior?

Thanks! Gláucio

glauciobb avatar Oct 15 '24 17:10 glauciobb