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

successURL: "/", of the .js file #3

Closed
infosrabah opened this issue Aug 11, 2018 · 8 comments
Closed

successURL: "/", of the .js file #3

infosrabah opened this issue Aug 11, 2018 · 8 comments
Labels
Q&A Questions and answers

Comments

@infosrabah
Copy link

infosrabah commented Aug 11, 2018

Hi Uroš,

Thank you for the new release, I know you were pulling off your hear... anyway. Your new release does refresh to the success URL '/' but however it is static inside the Javascript , It should take the successURL of the django create class and redirect to it.

I mean :

$.fn.modalForm = function (options) {
// Default settings
var defaults = {
modalID: "#modal",
modalContent: ".modal-content",
modalForm: ".modal-content form",
formURL: null,
successURL: "/",
errorClass: ".invalid"
};

the successURL :"/",
but I had set a different success_url = reverse_lazy('chauffeur:chauffeur-List') in my django ChauffeurCreateModal(CreateView) but it stills go to '/', can this take affect of the success_url or the Django Create class but not javascript, like a dynamic success_url.

You're close, so close.., any other hack ???

Thank you.

@trco
Copy link
Owner

trco commented Aug 11, 2018

@infosrabah Recheck the code under #6 in the docs. You should set the successURL when instantiating the modalForm with jQuery. Based on the new release the docs have changed. Of course for form's CBV to work you also have to set success_url in it. You just set successURL to {% url 'chauffeur:chauffeur-List' %} and it will work.

@infosrabah
Copy link
Author

Thank you,

Imagine that we got a list of object on the tempaltes, the templates variable of the list is chauffeur, so we iterate using obj, Could you give me an example of Javascript update instantiating of the modalForm, to pass the pk dynamically ?? for every items, because it is no sens to declare that script everytime we have an object in the list, to show edit modal, is gotta be a way !!!

Here's the Create that I did :

<script type="text/javascript">
$(document).ready(function() {

	    $("#createTest").modalForm({
	        formURL: "{% url "chauffeur:chauffeur-Create" %}"
			successURL: "{% url 'chauffeur:chauffeur-List' %}"
	    });

	});
	</script>

Or could you elaborate a update and a list senario, so when you clin on opdate object in the list it shows its own modal to edit its own data !! ???

thank you.

@infosrabah
Copy link
Author

This is new, and it may help :
http://brainstorm.it/snippets/ajax-form-submission-django/

@trco
Copy link
Owner

trco commented Aug 11, 2018

@infosrabah Ouu I see you didn't get the link yesterday in #1. It wasn't shown. I wrote this...

Regarding the updating of your objects, I believe it's doable with javascript. Check this post https://stackoverflow.com/questions/51572738/how-to-use-same-bootstrap-modal-for-2-different-submit-buttons-in-django/51629404#51629404 and my answer to get an idea on how to do it. The basic idea is to dynamically change action attribute of the form on modal opening. For example all your edit buttons would open the same modal but the data passed via data-id would be your different obj.id-s. After opening of the modal you would change the action attribute of the form to include obj.id. This is the idea.

Instructions for how to use my plugin with Update views are on my TODO list but unfortunately I don't have time for this at the moment. I'm planning to publish a webpage for django-bootstrap-modal-forms in near future and this will be included.

The blog post you attached is like 10h read :) I believe you will sooner or later find a solution.

@infosrabah
Copy link
Author

Thank you Uroš,

I really appreciate it, thank you,

and yes now I goit the Idea, using an a data attribute, thank you.

Thank's for the link again. It is verry informative, verry.

Let me know about the webpage/article.

Thank you.

@trco
Copy link
Owner

trco commented Aug 12, 2018

@infosrabah Check the new release 1.2.0 and new readme.rst. Remove form action in form's html, set UpdateView and url, and buttons with dynamic data-id attribute for editing in a for loop and than check how to bind modalForm to each editing button and set corresponding formURLs.

It had to add one line to support UpdateViews, so I decided to go for it :)

Good luck.

@infosrabah
Copy link
Author

infosrabah commented Aug 12, 2018

Hi Uroš,

If you went for it and went that far, why don't you make a real django project base on your Modal library that let people could clone it and run it, so it is gonna be easy for people to deploy it right away, I mean, you could avoid a loooots of questions and ...

and it is easy to set.

Waiting too for the project to be posted here.
Common Uroš, it is just a step to finalise your project,

Thank you so much,

@trco
Copy link
Owner

trco commented Aug 12, 2018

I'm on it and will be available in near future.

Release 1.2.0 https://github.com/trco/django-bootstrap-modal-forms/releases/tag/1.2.0 closes #3

@trco trco closed this as completed Aug 12, 2018
@trco trco added the Q&A Questions and answers label Aug 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Q&A Questions and answers
Projects
None yet
Development

No branches or pull requests

2 participants