Django Crispy Forms - Add a button through an assistant

I studied the Crispy-Forms documentation and I tried to add an extra button to one of my forms. WITH

self.helper.add_input(Button('back', "Back", css_class='btn'))

I can add a nice button. But Button () will not use the onclick or on_click attribute. So how can I add logic to this button? Adding an onclick event using jQuery is not a very nice solution ...

Thank!

Ron

+3
source share
2 answers

This is not enabled by default (afaik ..). If you just need it, you can use crispy HTML forms. Object layout

HTML('<input type="button" name="Save" onclick="do_whatever" />')

What do you dislike about jQuery? You can handle this pretty simple and versatile using something like:

$('form :submit.ajax_submit').live('click', function(e) {
    e.preventDefault();
    var my_form = $(this).parents('form');

    // do whatever
    alert(my_form.attr('id'));
    alert(my_form.attr('action'));
});

and then just pass the class:

Submit('save', 'save', css_class='ajax_submit')
+2

, Button onclick kwargs?

onclick="javascript here" Submit(), .

, , kwargs, - (.. ), HTML. 12 ( ), :

self.helper.add_input(Button('back', "Back", css_class='btn', onclick="alert('Neat!');"))
+4

All Articles