django-selectable icon indicating copy to clipboard operation
django-selectable copied to clipboard

AutoCompleteSelectWidget does not work with empty input

Open TZanke opened this issue 9 years ago • 4 comments
trafficstars

Hallo,

using a AutoCompleteSelect Widget, i encounter a problem when deleting a selected item.

  1. Open form with field (Charfield, default='', blank=True) and save form without changing anything. The field is empty and stays empty in the database

  2. Select a item with AutoCompleteSelect and save form. The item is now saved to the database.

  3. Try to delete the selection. In my case, the input field shown to the user is empty, but in the send POST data the old item id is not deleted. After saving form, the item is still in database.

How is it possible to delete a item to get an empty field again?

TZanke avatar May 17 '16 08:05 TZanke

Update:

after a click outside the input, the post data is correct. So it looks like only a js trigger does not work as expected. With allow_new there is also no problem.

TZanke avatar May 17 '16 11:05 TZanke

Yes the hidden input is cleared with the autocomplete plugin detects a change or select even which likely requires the input losing focus.

mlavin avatar May 17 '16 12:05 mlavin

After some research it looks like the change event is the right one for older browsers, new browsers support input to trigger all changes made by the user, for example paste.

Would be nice to have best modern browser support by django selectable.

TZanke avatar May 17 '16 13:05 TZanke

selectable does not directly bind to the input change/select/input. It catches the events propagated from the underlying widget from jQuery UI.

mlavin avatar May 17 '16 14:05 mlavin