root / env / lib / python2.7 / site-packages / django / contrib / admin / static / admin / js / prepopulate.js @ 1a305335
History | View | Annotate | Download (1.16 KB)
1 | 1a305335 | officers | (function($) { |
---|---|---|---|
2 | $.fn.prepopulate = function(dependencies, maxLength) { |
||
3 | /*
|
||
4 | Depends on urlify.js
|
||
5 | Populates a selected field with the values of the dependent fields,
|
||
6 | URLifies and shortens the string.
|
||
7 | dependencies - array of dependent fields id's
|
||
8 | maxLength - maximum length of the URLify'd string
|
||
9 | */
|
||
10 | return this.each(function() { |
||
11 | var field = $(this); |
||
12 | |||
13 | field.data('_changed', false); |
||
14 | field.change(function() {
|
||
15 | field.data('_changed', true); |
||
16 | }); |
||
17 | |||
18 | var populate = function () { |
||
19 | // Bail if the fields value has changed
|
||
20 | if (field.data('_changed') == true) return; |
||
21 | |||
22 | var values = [];
|
||
23 | $.each(dependencies, function(i, field) { |
||
24 | if ($(field).val().length > 0) { |
||
25 | values.push($(field).val());
|
||
26 | } |
||
27 | }) |
||
28 | field.val(URLify(values.join(' '), maxLength));
|
||
29 | }; |
||
30 | |||
31 | $(dependencies.join(',')).keyup(populate).change(populate).focus(populate); |
||
32 | }); |
||
33 | }; |
||
34 | })(django.jQuery); |