Comments (4)
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.
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.
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.
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)
- Option to choose search_fields for Select2MultipleWidget ? HOT 2
- support django3.0 HOT 2
- DjangoCMS 3.7 HOT 8
- Clean option no works properly HOT 2
- Issues when certain special characters appear in the field_id HOT 5
- How to add limitations to a RelatedFieldMixin HOT 1
- js config file HOT 3
- multi model select field HOT 1
- Release 7.2.1 on PIP HOT 6
- Interdependent selects for fields of one model HOT 3
- ModelSelect2Widget initial value is not selected HOT 6
- How do I load selected options for ModelSelect2MultipleWidget HOT 5
- Disable multiple select on tag widget HOT 5
- ModelSelect2TagWidget tagging new values HOT 9
- Implementation of Select2Widget with formsets. HOT 6
- Use https://<cdn>/ rather than //<cdn>/ for security? HOT 4
- Codecov migration to marketplace app HOT 2
- Django Select2 not working for formset when click on add more. HOT 1
- Django ModelSelect2MultipleWidget for ManyToMany field not working HOT 5
- Empty Dropdown Using ModelSelect2Widget HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-select2.