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

Fix: Handle undefined django object to prevent TypeError. Fixes: #313 #314

Merged
Merged
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
45 changes: 24 additions & 21 deletions ajax_select/static/ajax_select/js/ajax_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,25 +231,28 @@
* In django >= 1.10 we could try to rely on input.trigger('change')
* and avoid this hijacking, but the id and repr isn't passed.
*/
djangoJQuery(document).ready(function () {
var djangoDismissAddRelatedObjectPopup =
window.dismissAddRelatedObjectPopup;
if (!djangoDismissAddRelatedObjectPopup) {
throw new Error("dismissAddAnotherPopup not found");
}

window.dismissAddRelatedObjectPopup = function (win, newId, newRepr) {
// Iff this is an ajax-select input then close the window and
// trigger didAddPopup
var input = $("#" + win.name.replace("__1", ""));
if (input.length && input.data("ajax-select")) {
win.close();
// note: newRepr is django's repr of object, not the Lookup's formatting of it.
input.trigger("didAddPopup", [newId, newRepr]);
} else {
// Call the normal django set and close function.
djangoDismissAddRelatedObjectPopup(win, newId, newRepr);
if (djangoJQuery) {
// only for Django Admin
djangoJQuery(document).ready(function () {
var djangoDismissAddRelatedObjectPopup =
window.dismissAddRelatedObjectPopup;
if (!djangoDismissAddRelatedObjectPopup) {
throw new Error("dismissAddAnotherPopup not found");
}
};
});
})(window.jQuery, window.django.jQuery);

window.dismissAddRelatedObjectPopup = function (win, newId, newRepr) {
// Iff this is an ajax-select input then close the window and
// trigger didAddPopup
var input = $("#" + win.name.replace("__1", ""));
if (input.length && input.data("ajax-select")) {
win.close();
// note: newRepr is django's repr of object, not the Lookup's formatting of it.
input.trigger("didAddPopup", [newId, newRepr]);
} else {
// Call the normal django set and close function.
djangoDismissAddRelatedObjectPopup(win, newId, newRepr);
}
};
});
}
})(window.jQuery, window.django && window.django.jQuery);
Loading