AutoCompleteSelectWidget doesn't respond when underlying <input hidden> value gets changed.
Given a field foo = selectable.forms.AutoCompleteSelectField(...), doing $("#id_foo_1").val("3").trigger('change') does not cause the text to update.
This is something that select2 supports. If you go to their webpage and go to the "Loading Remote Data" section, open up a JS debugger console, and run code like $("#e6").val('16010').trigger('change'), you'll see the widget text updates appropriately and can even see it making the proper requests in the network tab. (I'm using Chrome but I assume Firefox has similar dev tools.)
This doesn't seem like a problematic change so I am going to start working on a patch.
- Bitbucket: https://bitbucket.org/mlavin/django-selectable/issue/101
- Originally Reported By: leo-the-manic
- Originally Created At: 2013-07-16T17:23:20.600
Nothing in my reply nor the mailing list thread implies building a JSON service to get this data. If you are setting the value manually you clearly already have a means of getting the data. Using the select method over setting the value manually will also set the text value and in the case of the multiple select will build the list item for removal. It will also ensure that the djselectableselect event is fired for other listeners.
Original Comment By: Mark Lavin
If you're just suggesting I build a JSON service to get the data and inject it manually, that's certainly the route to go, but I don't understand the use of using the 'select' method vs. just setting the fields directly.
Original Comment By: leo-the-manic
Note that you can do programmatic selection on the client side with the select method. See a previous discussion on the mailing list https://groups.google.com/d/msg/django-selectable/q2iQco8Jrkw/vTA39HuRMjgJ
Original Comment By: Mark Lavin
After tinkering with jQueryUI's auto-complete I found that it only operates on text fields. In contrast, select2 must be activated on an field, so it makes sense for select2 to come with such a feature out of the box, whereas the same idea doesn't apply to jQueryUI's autocomplete.
The link between the autocomplete text field and a hidden input is established by django-selectable, so if the feature in this ticket were to exist anywhere it would exist in this project. However I presume you believe this is out of the scope of your project so I won't re-open this ticket.
Original Comment By: leo-the-manic
Oh, right. I'm a migrant from django-select2, where the underlying select2 widget did support this feature but the django-select2 package ended up breaking it. I haven't properly reset my brain, but you're right, this isn't relevant to this project. My apologies!
Original Comment By: leo-the-manic
The primary goal of this project is to be an easy bridge between the Django form system and the jQuery UI autocomplete. If this functionality doesn't exist in the jQuery UI code then it isn't likely to be included here.
Original Comment By: Mark Lavin
@mlavin The problem with no change action on hidden form change is quite easily solvable with following JavaScript:
// Fix triggering chaining on hidden company field
$( "#id_company_0" ).on( "djselectableselect", function( event, ui ) {
$('#id_company_1').change();
} );
but I spend half of day searching for this solution. What about adding it to documentation?
That seems like a reasonable inclusion to me.