Skip to content

Commit d5e0d74

Browse files
committed
Merge branch 'release/1.5.1'
2 parents 2625814 + 0fad5c4 commit d5e0d74

File tree

6 files changed

+66
-24
lines changed

6 files changed

+66
-24
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
# Change Log
22

3+
## [1.5.1](https://github.com/crucialfelix/django-ajax-selects/tree/1.5.1) (2016-10-13)
4+
[Full Changelog](https://github.com/crucialfelix/django-ajax-selects/compare/1.5.0...1.5.1)
5+
6+
**Implemented enhancements:**
7+
8+
- Prefer document.createElement to document.write [\#182](https://github.com/crucialfelix/django-ajax-selects/issues/182)
9+
10+
**Fixed bugs:**
11+
12+
- fix: add related for multiple select [\#184](https://github.com/crucialfelix/django-ajax-selects/pull/184) ([crucialfelix](https://github.com/crucialfelix))
13+
314
## [1.5.0](https://github.com/crucialfelix/django-ajax-selects/tree/1.5.0) (2016-09-05)
415
[Full Changelog](https://github.com/crucialfelix/django-ajax-selects/compare/1.4.3...1.5.0)
516

617
- Added Support for Django 1.10
718
- Dropped Django 1.5
819

20+
**Fixed bugs:**
21+
22+
- Initial fields are duplicated when new row added. [\#94](https://github.com/crucialfelix/django-ajax-selects/issues/94)
23+
924
**Closed issues:**
1025

1126
- ValueError in Django 1.10 [\#177](https://github.com/crucialfelix/django-ajax-selects/issues/177)

ajax_select/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""JQuery-Ajax Autocomplete fields for Django Forms."""
2-
__version__ = "1.4.3"
2+
__version__ = "1.5.1"
33
__author__ = "crucialfelix"
44
__contact__ = "[email protected]"
55
__homepage__ = "https://github.com/crucialfelix/django-ajax-selects/"

ajax_select/static/ajax_select/js/ajax_select.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
window.addEventListener('load', function() {
12

2-
(function($) {
3-
'use strict';
3+
var $ = window.jQuery;
44

55
$.fn.autocompleteselect = function(options) {
66
return this.each(function() {
@@ -184,22 +184,24 @@
184184
/* Called by the popup create object when it closes.
185185
* For the popup this is opener.dismissAddRelatedObjectPopup
186186
* Django implements this in RelatedObjectLookups.js
187+
* In django >= 1.10 we can rely on input.trigger('change')
188+
* and avoid this hijacking.
187189
*/
188190
var djangoDismissAddRelatedObjectPopup = window.dismissAddRelatedObjectPopup || window.dismissAddAnotherPopup;
189191
window.dismissAddRelatedObjectPopup = function(win, newId, newRepr) {
190-
// This may be called for ajax-select inputs or for other inputs.
191-
// Call the original which sets the input (just the pk)
192-
// calls input.trigger('changed') if >= 1.10
193-
// and closes the window.
194-
if (djangoDismissAddRelatedObjectPopup) {
195-
djangoDismissAddRelatedObjectPopup(win, newId, newRepr);
196-
} else {
192+
// Iff this is an ajax-select input then close the window and
193+
// trigger didAddPopup
194+
var name = window.windowname_to_id(win.name);
195+
var input = $('#' + name);
196+
if (input.data('ajax-select')) {
197197
win.close();
198+
// newRepr is django's repr of object
199+
// not the Lookup's formatting of it.
200+
input.trigger('didAddPopup', [newId, newRepr]);
201+
} else {
202+
// Call the normal django set and close function.
203+
djangoDismissAddRelatedObjectPopup(win, newId, newRepr);
198204
}
199-
var name = window.windowname_to_id(win.name);
200-
// newRepr is django's repr of object
201-
// not the Lookup's formatting of it.
202-
$('#' + name).trigger('didAddPopup', [newId, newRepr]);
203205
}
204206
// Django renamed this function in 1.8
205207
window.dismissAddAnotherPopup = window.dismissAddRelatedObjectPopup;
@@ -243,4 +245,4 @@
243245
});
244246
});
245247

246-
})(window.jQuery);
248+
}, {once: true});
Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
1-
// load jquery and jquery-ui if needed
2-
// into window.jQuery
3-
if (typeof window.jQuery === 'undefined') {
4-
document.write('<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"><\/script><script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"><\/script><link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />');
5-
} else if(typeof window.jQuery.ui === 'undefined' || typeof window.jQuery.ui.autocomplete === 'undefined') {
6-
document.write('<script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"><\/script><link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />');
7-
}
1+
(function(w) {
2+
/**
3+
* load jquery and jquery-ui if needed
4+
*/
5+
6+
function not(thing) {
7+
return typeof thing === 'undefined';
8+
}
9+
10+
function loadJS(src) {
11+
var script = document.createElement('script');
12+
script.src = src;
13+
document.head.appendChild(script);
14+
}
15+
16+
function loadCSS(href) {
17+
var script = document.createElement('link');
18+
script.href = href;
19+
script.type = 'text/css';
20+
script.rel = 'stylesheet';
21+
document.head.appendChild(script);
22+
}
23+
24+
if (not(w.jQuery)) {
25+
loadJS('//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js');
26+
}
27+
28+
if (not(w.jQuery) || not(w.jQuery.ui) || not(w.jQuery.ui.autocomplete)) {
29+
loadJS('//code.jquery.com/ui/1.10.3/jquery-ui.js');
30+
loadCSS('//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css');
31+
}
32+
})(window);

docs/source/Outside-of-Admin.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ajax_selects does not need to be in a Django admin.
55

66
When placing your form on the page be sure to include the static assets:
77

8-
{{ form.meta }}
8+
{{ form.media }}
99

1010
This includes the javascript and css files.
1111

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setup(
1111
name='django-ajax-selects',
12-
version='1.5.0',
12+
version='1.5.1',
1313
description='Edit ForeignKey, ManyToManyField and CharField in Django Admin using jQuery UI AutoComplete.',
1414
author='Chris Sattinger',
1515
author_email='[email protected]',

0 commit comments

Comments
 (0)