Prepend Text in Crispy Forms - Django
I have a form that works generally as expected, but I am trying to prepend some text on one of the fields to make it more user-friendly. In this case, all entries in the "RFP Control Number" field should start with "RFP-" so I want to use crispy forms to prepend that text. I have followed the setup in the crispy forms documentation to the best of my ability, but am not having any luck getting the prepended text to show up. Any ideas? The documentation is linked below:
https://django-crispy-forms.readthedocs.io/en/latest/layouts.html
and a simplified version of my form is included below as well. Greatly appreciate any help! Please let me know if you have any questions, or if any additional information is needed.
class ProposalForm(forms.ModelForm): class Meta: model = Proposal fields = [ 'organization', 'rfp_control_number', ]
def __init__(self, *args, **kwargs):
super(ProposalForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_method = 'POST'
self.helper.layout = Layout(
'organization',
PrependedText('rfp_control_number', 'RFP-'),
Submit('submit', 'Submit', css_class='btn btn-primary'),
)
I tried the few different syntaxes listed in the documentation website included in my post to no avail. I have looked online for articles and watched YouTube videos about Crispy Forms, but I have not found anything that covers this directly. This is a simplified version of my form to test on.
def __init__(self, initial=None, *args, **kwargs):
initial[{field name}] = 'RFP-'
super().__init__(initial, *args, **kwargs)