Git Product home page Git Product logo

Comments (4)

leo-the-manic avatar leo-the-manic commented on August 17, 2024

I thought I'd hop in, fix the issue and give you a pull request... But I can't really make heads or tails of the largely undocumented code. Do let me know if you get this working, but for the time being I'm just gonna have to roll my own stuff...

from django-select2.

applegrew avatar applegrew commented on August 17, 2024

Hey thanks for the excellent testcase. It makes the job much easier. 👍

Firing a change event is not the right thing to do here. That is fired when user makes a selection. In this case 'Human Resource' options needs to be queried first. It cannot be selected since that is not known to be a valid option yet. Now ideally Select2 should have provided an API to programmatically trigger such queries but I could not find any (ref).

So, currently one way of doing this is by using this JS code instead:-

$('#id_department').select2('data', {id: 2, text:'Human Resource'})

That is a standard Select2 API for such cases. Note that here we pass the display text too. The curent heave_data.js is failing since it could not find the display text. In case of valid selections, the display texts are always available, hence there is no check for possible failure.

from django-select2.

leo-the-manic avatar leo-the-manic commented on August 17, 2024

I believe what I am looking for is in fact supported behavior.

If you go here:
http://ivaynberg.github.io/select2/

One part of the page has the headline "Reacting to external value changes" where the example code is more or less the same as my example code, and where the stated reason is more or less the same as my stated reason.

If you go to the section called "Loading Remote Data," they have an example widget which is linked to a RottenTomatoes database. The <input type="hidden"> for this widget has the id e6. You can use a Javascript console in Chrome, Firefox, etc. to run code like $("#e6").attr("value", "14000").change(). You can see the text field update, it will make the proper GET request, etc. This is exactly the type of functionality I am trying to get and it looks like it's built-in to select2. (If you want to try with more IDs, it seems like RottenTomatoes wants an ID between ten thousand and twenty thousand.)

I can't really trivially fix the problem in the same way this test case can be trivially fixed. I have a field set. One field in that set is a foreign-key field which has 1000+ records in the database, controlled by a select2 widget. When the user autocompletes the entire fieldset, the select2 widget text doesn't update. Calling select2 directly is a solution I'd like to avoid since it'll start coupling the rest of my frontend code to select2 more than is necessary.

from django-select2.

applegrew avatar applegrew commented on August 17, 2024

Ok I see now. Select2 uses initSelction to convert unknown ids to text. In current implementation of heavy.js there is no such support since AutoView too has no such support. So, this needs some significant backend changes.

from django-select2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.