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

Dynamically definition of the formURL in the create button. #243

Open
glauciobb opened this issue Oct 15, 2024 · 0 comments
Open

Dynamically definition of the formURL in the create button. #243

glauciobb opened this issue Oct 15, 2024 · 0 comments

Comments

@glauciobb
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@glauciobb and others