Skip to content

using select2 'scoped change' event to trigger options refresh #79

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
14 changes: 5 additions & 9 deletions autoform-select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,11 @@ Template.afSelect2.onRendered(function () {
}
});

var currentValues = $s.val();
if ((!currentValues && values.length > 0) ||
(currentValues && currentValues.toString() !== values.toString())) {
// select2 requires that we trigger change event
// for it to realize it needs to update the select2 list.
// We do it only if values have actually changed,
// which should help prevent autosave infinite looping.
$s.val(values).trigger('change');
}
// Using select2' "scoped change" event
// to avoid autosubmit when in an autosave form
// https://select2.org/programmatic-control/events#limiting-the-scope-of-the-change-event
$s.val(values).trigger('change.select2');

});
});

Expand Down