2

I try to reorder a form fields but I do not find a proper way. This is my form

class UserSignupForm(SignupForm):
    def __init__(self, *args, **kwargs):
        super(UserSignupForm, self).__init__(*args, **kwargs)
        self.fields["first_name"] = CharField(label="Prénom")
        self.fields.keyOrder = ['first_name', 'email', 'password1', 'password2']

and the render into the template

<form class="signup" id="user_signup_form" method="post" action="{% url 'user_signup' %}">
            {% csrf_token %}
            {{ form|bulma }}
            {% if redirect_field_value %}
                <input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}"/>
            {% endif %}
            <button type="submit" class="button is-primary">{% trans "Sign Up" %}</button>
        </form>

as you can see, I override the SignupForm from django-allauth with a field addition. Then, I would like to reorder fields to set the first_name as 1st fields. Unfortunately, I do not find a solution and don't want to edit the html render.

Any solution ?

sbm54
  • 75
  • 6

1 Answers1

2

@brianD helped me finding a solution, this is the updated form:

class UserSignupForm(SignupForm):
    first_name = CharField(label="Prénom")
    field_order = ['first_name', 'email', 'password1', 'password2']
sbm54
  • 75
  • 6