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

initialize select2 widget #31

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

pjpassa
Copy link
Contributor

@pjpassa pjpassa commented Aug 18, 2016

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.

PJ Passalacqua and others added 3 commits June 7, 2016 16:24
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
@coveralls
Copy link

coveralls commented Aug 18, 2016

Coverage Status

Coverage remained the same at 96.198% when pulling f37013c on worthwhile:feat/initialize-select2 into 119c76d on modlinltd:develop.

$.get(choices_url, function(data) {
if (value) {
data.results.push({'id': value, 'text': value})
Copy link
Member

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.

Copy link
Contributor Author

@pjpassa pjpassa Aug 19, 2016

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.

Copy link
Member

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 ?

@asfaltboy
Copy link
Member

asfaltboy commented Aug 19, 2016

Hi @pjpassa, thanks again for putting work on the project.

Please see my comments on commit b48dfe8. Generally speaking this seems like the right place to resolve this issue.

Unfortunately, I won't have time to test any time soon, and we still don't have a frontend test suite (issue #19).

@mrname
Copy link

mrname commented Jun 28, 2018

I just merged master into this branch locally and tested it out. Things seem to work as promised:

advanced_filters_pr_31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Editing a pre-initialized form does not show easy-select2
5 participants