Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update text of submit button in wtforms

I have a form, that will be used for a new submit and updates. My question is about the text of the submit button. I want to change the text to New submit and to New update, depending on the situation. This is purely informative.

class Interview(Form):
    ...
    submit = SubmitField('New submit')  

If possible, i want to avoid create a new class, with exactly same fields, only because of the text of submit.

like image 540
user2990084 Avatar asked Aug 20 '15 00:08

user2990084


2 Answers

Old question, but for anyone else coming across this, an alternative is to just set it from code before rendering the template:

if is_submit:
    form.submit.label.text = 'New submit'
else:
    form.submit.label.text = 'New update'

return render_template(...)
like image 153
Barney Avatar answered Nov 09 '22 06:11

Barney


The correct way to do this with mixins:

class InterviewMixin():
    ...

class InterviewSubmit(Form, InterviewMixin):
    submit = SubmitField('New submit')

class InterviewUpdate(Form, InterviewMixin):
    submit = SubmitField('New update')
like image 39
nathancahill Avatar answered Nov 09 '22 07:11

nathancahill