sergiodlopes / jquery-flexdatalist

Flexible input autocomplete/datalist plugin for jQuery
http://projects.sergiodinislopes.pt/flexdatalist/
MIT License
364 stars 84 forks source link

Auto-focus at the bottom when deleting items #189

Open ninsuo opened 5 years ago

ninsuo commented 5 years ago

Hello there,

Thanks for the great work, your project really helps on complex mobile-first forms.

I've noticed a small issue though, that may deserve attention on large data lists.

screen shot 2018-12-15 at 00 16 52

When you delete an item at the top of the list, focus is automatically made on the flexdatalist input, so on mobile device, you scroll down below the last element, and need to scroll up again if you with to remove other items at the top.

To get rid of this behavior, I added a hack that toggles disabled on the field during after:remove event, but that's not elegant at all:

        $('#people').on('after:flexdatalist.remove', function () {
            $('#people-flexdatalist').prop('disabled', 'disabled');
            setTimeout(function () {
                $('#people-flexdatalist').prop('disabled', false);
            }, 0);
        });

There may be a cleaner solution 😄

Cheers, Alain