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:

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'))
                                     "Change password",
                                     onclick="javascript:location.href = \
        # ============= SOLUTION ===============                             
        self.helper.add_input(Button('back', 'Back', 
    class Meta:
        model = Surfer

results matching ""

    No results matching ""