Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoCompleteSelectWidget doesn't respond when underlying <input hidden> value gets changed. #101

Open
mlavin opened this issue Nov 10, 2013 · 10 comments

Comments

@mlavin
Copy link
Owner

mlavin commented Nov 10, 2013

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.


@mlavin
Copy link
Owner Author

mlavin commented Nov 10, 2013

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

@mlavin
Copy link
Owner Author

mlavin commented Nov 10, 2013

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

@mlavin
Copy link
Owner Author

mlavin commented Nov 10, 2013

That isn't really related to what this ticket is about.


Original Comment By: leo-the-manic

@mlavin
Copy link
Owner Author

mlavin commented Nov 10, 2013

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

@mlavin
Copy link
Owner Author

mlavin commented Nov 10, 2013

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

@mlavin
Copy link
Owner Author

mlavin commented Nov 10, 2013

Confusion with feature from django-select2.


Original Comment By: Mark Lavin

@mlavin
Copy link
Owner Author

mlavin commented Nov 10, 2013

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

@mlavin
Copy link
Owner Author

mlavin commented Nov 10, 2013

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 mlavin closed this as completed Nov 10, 2013
@PetrDlouhy
Copy link
Contributor

@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?

@mlavin
Copy link
Owner Author

mlavin commented Apr 4, 2017

That seems like a reasonable inclusion to me.

@mlavin mlavin reopened this Apr 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants