add a back button to crispy form

Date: April 18th 2016
Last updated: April 18th 2016

This is the second time I have encountered JavaScript while trying to create buttons for crispy forms. This entry follows on from PasswordChangeForm and add buttons to crispy forms.

The example I used to create this backbutton came from here: http://stackoverflow.com/questions/524992/django-templates-create-a-back-link

class SurferForm(forms.ModelForm):
    #<- snipped ->

    def __init__(self, *args, **kwargs):
        super(SurferForm, self).__init__(*args, **kwargs)
        #<- snipped ->
        self.helper = FormHelper()
        self.helper.add_input(Submit('submit', u'Submit'))
        self.helper.add_input(Button('changepassword', 
                                     "Change password",
                                     css_class='btn',
                                     onclick="javascript:location.href = \
                                     '/changepassword';"))
        # ============= SOLUTION ===============                             
        self.helper.add_input(Button('back', 'Back', 
                                     css_class='btn-success',
                                     onClick="javascript:history.go(-1);"))                            
        #=======================================
    class Meta:
        model = Surfer

results matching ""

    No results matching ""