The "flask_admin" "select2" for "flask_mongoengine.ListField" sorts the input before sending the http request for saving

24 views Asked by At

I am using flask, flask_mongoengine and having issues with the sorting of the input in a ListField model field, when edited in the admin panel. The ordering is important to me, so I want the same order to be ratained when saving the user input to mongo. Unfortunately, I think the select2.min.js, is sorting the field input before sending http request to the server for saving, so it goes there alphabetically. Or more precisely seems the new additions are sorted alphabetically and put on top of the previous. Here is the model configuration I have:

class JfDefinition(MongoEngine.Document):
    _id = db.StringField(max_length=200, primary_key=True)

class IndMappings(MongoEngine.Document):
    jf_alternates = db.ListField(db.ReferenceField(JfDefinition))

Here is how it looks in flask admin before clicking the "Save" button, notice that it is added in the order "r.." , "a..", "e..": flask_admin select2 before saving

And this is how it is in the Form data in the http request, after clicking "Save". Please notice that the initial ordering of "r.." , "a..", "e.." changed to "a..", "e..", "r..":

flask_admin select2 order changed in the http form data

Is it possible to modify the editor to stop sorting, or is it possible to use a different editor that retains the editor's sorting? Please notice that I have thousands of "JfDefinition" so it would need some ajax capabilities like the select2.

I tried changing the admin's "form_base_class" on the "IndMappingsView" serverside, but it seems the sorting happens in a javascript on the browser already.

0

There are 0 answers