Possible duplicate: WTForms - dynamic labels by passing argument to constructor?
I'm creating a form using WTForms and Flask that lets users enter a new contact:
class ContactForm(Form):
firstName = StringField("First Name", [validators.Required("Please enter your first name.")])
lastName = StringField("Last Name", [validators.Required("Please enter your last name.")])
email = StringField('Email')
phoneNo = StringField('Phone #')
notes = StringField('Notes', widget=TextArea())
submit = SubmitField("Create Contact")
def __init__(self, *args, **kwargs):
Form.__init__(self, *args, **kwargs)
I'd like to use this form when the user creates a new contact and also when the user wants to edit an existing contact, and so I need to be able to change some of the labels displayed to the user dynamically (in particular I need to change the text on the submit button). I'd like to pass in a string to the constructor for that purpose, but I'm not that familiar with either Python or WTForms. Can someone help me figure out how to do it?