0

I am trying to override the helptext that is set in my model in the wagtail admin (an edit view). I have tried the code below but the text is not changed, why is that?

    class MemberRegistrationEditView(EditView):

        def get_form(self):
            form = super().get_form()
            form.base_fields.get("own_email").help_text = "Test"
            return form
Andreas
  • 1,421
  • 3
  • 16
  • 32
  • maybe first use `print()` in `get_form` to see if this function is executed. – furas Nov 23 '21 at 10:11
  • I have added a breakpoint to check, and it is hit. – Andreas Nov 23 '21 at 10:42
  • you could use `print()` to check what you have in `.help_text` before assigning `Test`. Maybe it doesn't exist and you use wrong field. – furas Nov 23 '21 at 11:30
  • @furas I have used breakpoints to check that it is actually overriding the correct field, but that does not reflect when the full page is loaded – Andreas Nov 26 '21 at 12:14

1 Answers1

0

Thanks for posting your question. I understand what you're trying to achieve i think. Generally speaking though, and others may disagree, but I would do this inside of the forms dunder init function (__init__)

class MyForm(forms.Form):
    def __init__(self, *args, **kwargs):
        self.base_fields['own_email'].help_text = "Test"
        super().__init__(*args, **kwargs) 

Its worth noting that this will replace the help text for every time this particular form is used.

If you want to do something specific while in a certain view, then I would recommend simply inheriting the form you want instead of forms.Form and then replace the form attribute on the view for your new form.

Swift
  • 1,663
  • 1
  • 10
  • 21