-
Notifications
You must be signed in to change notification settings - Fork 173
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
initialize select2 widget #31
base: develop
Are you sure you want to change the base?
Conversation
This commit changes the way the URLs are declared to avoid RemovedInDjango110Warning messages. The old way, using django.conf.urls.patterns(), is deprecated and will be removed in Django 1.10
$.get(choices_url, function(data) { | ||
if (value) { | ||
data.results.push({'id': value, 'text': value}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't the currently selected value already exist in the results? This does feel redundant, as you mentioned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value actually might not exist in the results. One example is choices being disabled for a field. To avoid duplication though, there should be a check to see if the value is currently in data. No reason to add it if it is already there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. In that case, how about we add the value into results only if it does not exist already ?
This merge request allows the select2 widget to pre-populate with the current value. It should also fix Issue 22.
There is a side effect to how I fixed this, which I think is OK. If the value is not in the list returned by the ajax call it is added to the beginning of the list. This does also make it easy to switch back to the old value if you want to.
Also, if the value is in the list returned from the ajax call, it is in the list twice. This behavior is less desired, but it can be useful if you have a long list to see what the previous value was.