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
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions advanced_filters/static/advanced-filters/advanced-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ var OperatorHandlers = function($) {
MODEL_LABEL) + '/' + field;
var input = $(elm).parents('tr').find('input.query-value');
input.select2("destroy");
var value = input.val();
$.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 ?

}
input.select2({'data': data, 'createSearchChoice': function(term) {
return { 'id': term, 'text': term };
Copy link
Member

@asfaltboy asfaltboy Aug 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could simply call input.val(value)" before the return call to select the pre-initialized value as current.

}});
Expand Down Expand Up @@ -127,6 +131,7 @@ var OperatorHandlers = function($) {
$(this).data('pre_change', $(this).val());
}).change();
});
self.initialize_select2(this)
};

self.destroy = function() {
Expand Down