Open dhait opened 2 weeks ago
Flask-Admin currently relies on WTForm's ordering when rendering fields.
Flask-Admin adds fields to the form based on form_columns
, and generally WTForms respects this, so I suspect this bug is caused by the form being generated and then you "adding" (overriding) the company
field, which maybe sends it to the back of the list of fields on the form.
It does look like flask-admin docs say form_columns
controls the rendering order of fields, so I think we should fix this.
At a glance this appears to be the likely culprit: https://github.com/pallets-eco/flask-admin/blob/2fae681e641d4377f60e9c514110809b24a65ed0/flask_admin/templates/bootstrap4/admin/lib.html#L195-L202
In the mean time, a workaround might be to set form_rules
as per https://flask-admin.readthedocs.io/en/latest/api/mod_contrib_sqla/#flask_admin.contrib.sqla.ModelView.form_rules. As form_rules
overrides the ordering of fields that comes from wtforms.
I've added a scaffold_form() function on my view, in order to override the querying of a specific child field. But it is put at the bottom of the form, instead of at the top, as requested by 'form_columns'.
I expect that the 'Company' field will be at the top of the 'edit' form (disabled). Instead, it is at the very bottom after all the other fields.
Environment: