Reputation: 3617
I have two buttons in my django-crispy-form
self.helper.add_input(Submit('submit', 'Submit'))
self.helper.add_input(Button('cancel', 'Cancel'))
The submit button works just fine, the cancel button does nothing. As i am quite new to django/pyhton, how would i add a goto url (e.g. url below) to the action of the cancel button?
url(r'^customeroverview/$', 'customer.views.customeroverview', name='customeroverview'),
I have read that this is possible with JQuery, but this is something i never used. Eager to learn so if this would be the best option i am open to suggestions. Keep in mind i use the crispy form and want to use ass little html as possible.
If jQuery is used;
Upvotes: 3
Views: 2723
Reputation: 19969
This page has another way:
HTML("""<a role="button" class="btn btn-default"
href="{% url "some_cancel_url" %}">Cancel</a>"""),
So some_cancel_url
is the name of the url you want to go to.
Seems a little hackish, but I think an anchor is better than javascript. Better for search engines, people without JS or simply for checking out the link by hovering.
Upvotes: 2
Reputation: 3617
I figured it out, I used the following;
self.helper.add_input(Button('cancel', "Cancel", css_class='btn', onclick="javascript:location.href = '/customeroverview';"))
Upvotes: 4