Skip to content

Comparison enhancement and select2SortableOrder() binding change proposal #4

@matteopoile

Description

@matteopoile

First of all, I have got a quite complex interface with some simple select2 and in some cases up to 20/30 select2 + select2Sortable that use select2 formatSelection function.

In this case i prefer to bind the select2SortableOrder on jQuery UI stop and on original select change.
Sorting 300 items of a single select2Sortable instance takes around 100 milliseconds on my hardware while sorting 20/30 instances on form submit will take 2/3 seconds...
I prefer a lot of little sorts instead of a big one but this is questionable.
Maybe the best way would be choose a default and add a parameter to let the developer change the default behaviour (bind: sortableStop|formSubmit). No time to develop this now :(.

I spotted a bug using select2 formatSelection function. In select2Sortable there's a weak text comparison between the original option text and the visualized li.select2-search-choice text to sort the original select option. This will fail if you format li.select2-search-choice content trough select2 formatSelection function so I change that option text comparison with an option value comparison.

At the end of select2SortableOrder there are a call to select2SortableDestroy() followeb by a call to select2Sortable() that don't take in consideration the new and optional sortableOptions argument passed on select2Sortable initilization. It seems it works fine commenting that 2 functions calls but I'm not sure removing them will not lead to other problems I didn't spotted yet.

Hoping my english will be understandable, your opinion will be very appreciated.

P.S.: Have you ever tried select2Sortable on a select2 ajax configured?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions