Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This happens because the fields ordering is defined by UnboundField.creation_counter class, which uses the order the Field class appears in the code. </p> <pre><code>&gt;&gt;&gt; x1 = UserForm() &gt;&gt;&gt; x2 = UpdateUserForm() &gt;&gt;&gt; [(f[0], f[1].creation_counter) for f in x1._unbound_fields] [('first_name', 22), ('last_name', 23), ('middle_name', 24), ('username', 25), ('password', 26), ('email', 27)] &gt;&gt;&gt; [(f[0], f[1].creation_counter) for f in x2._unbound_fields] [('first_name', 22), ('last_name', 23), ('middle_name', 24), ('username', 25), ('email', 27), ('password', 28)] &gt;&gt;&gt; </code></pre> <p>As this is hard to solve (because wtforms try to be magic using this approach), the best way to deal with this is to define the fields in the desired order.</p> <pre><code>class BaseForm(Form): first_name = TextField(u'First name', [validators.Required()]) last_name = TextField(u'Last name', [validators.Required()]) middle_name = TextField(u'Middle name', [validators.Required()]) username = TextField(u'Username', [validators.Required()]) class UserForm(BaseForm): password = TextField(u'Password', [validators.Required()], widget=PasswordInput()) email = TextField(u'Email', [validators.Optional(), validators.Email()]) class UpdateUserForm(BaseForm): password = TextField(u'Password', [validators.Optional()], widget=PasswordInput()) email = TextField(u'Email', [validators.Optional(), validators.Email()]) </code></pre> <p>But if you are perfectionist or need to adhere to the <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself" rel="nofollow">DRY principle</a>:</p> <pre><code>class BaseForm(Form): first_name = TextField(u'First name', [validators.Required()]) last_name = TextField(u'Last name', [validators.Required()]) middle_name = TextField(u'Middle name', [validators.Required()]) username = TextField(u'Username', [validators.Required()]) class UserForm(BaseForm): password = TextField(u'Password', [validators.Required()], widget=PasswordInput()) class UpdateUserForm(BaseForm): password = TextField(u'Password', [validators.Optional()], widget=PasswordInput()) BaseForm.email = TextField(u'Email', [validators.Optional(), validators.Email()]) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload