diff --git a/django/contrib/admin/static/admin/js/prepopulate.js b/django/contrib/admin/static/admin/js/prepopulate.js
index 24f24f9..27a1498 100644
a
|
b
|
|
14 | 14 | field.change(function() { |
15 | 15 | field.data('_changed', true); |
16 | 16 | }); |
| 17 | if (field.val()) { |
| 18 | field.data('_filled', true); |
| 19 | } else { |
| 20 | field.data('_filled', false); |
| 21 | } |
17 | 22 | |
18 | 23 | var populate = function () { |
19 | 24 | // Bail if the fields value has changed |
20 | | if (field.data('_changed') == true) return; |
| 25 | if (field.data('_changed') == true || field.data('_filled') == true) return; |
21 | 26 | |
22 | 27 | var values = []; |
23 | 28 | $.each(dependencies, function(i, field) { |
diff --git a/django/contrib/admin/templatetags/admin_modify.py b/django/contrib/admin/templatetags/admin_modify.py
index cecc6ed..19d696b 100644
a
|
b
|
def prepopulated_fields_js(context):
|
9 | 9 | the prepopulated fields for both the admin form and inlines. |
10 | 10 | """ |
11 | 11 | prepopulated_fields = [] |
12 | | if context['add'] and 'adminform' in context: |
| 12 | if 'adminform' in context: |
13 | 13 | prepopulated_fields.extend(context['adminform'].prepopulated_fields) |
14 | 14 | if 'inline_admin_formsets' in context: |
15 | 15 | for inline_admin_formset in context['inline_admin_formsets']: |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 1633fba..b7a5dd9 100644
a
|
b
|
class SeleniumPrePopulatedFirefoxTests(AdminSeleniumWebDriverTestCase):
|
3270 | 3270 | slug2='option-one-tabular-inline-ignored-characters', |
3271 | 3271 | ) |
3272 | 3272 | |
| 3273 | def test_populate_existing_entry(self): |
| 3274 | item = MainPrepopulated.objects.create( |
| 3275 | name=' this is the mAin nÀMë', |
| 3276 | pubdate='2012-02-18', |
| 3277 | status='option two', |
| 3278 | slug1='main-name-2012-02-18', |
| 3279 | slug2='option-two-main-name' |
| 3280 | ) |
| 3281 | self.admin_login(username='super', |
| 3282 | password='secret', |
| 3283 | login_url='/test_admin/admin/') |
| 3284 | |
| 3285 | self.selenium.get('%s%s' % (self.live_server_url, |
| 3286 | '/test_admin/admin/admin_views/' |
| 3287 | 'mainprepopulated/{}/'.format(item.id))) |
| 3288 | |
| 3289 | self.selenium.find_element_by_css_selector('#id_name').send_keys(' the best') |
| 3290 | |
| 3291 | slug1 = self.selenium.find_element_by_css_selector('#id_slug1').get_attribute('value') |
| 3292 | slug2 = self.selenium.find_element_by_css_selector('#id_slug2').get_attribute('value') |
| 3293 | |
| 3294 | self.assertEqual(slug1, 'main-name-best-2012-02-18') |
| 3295 | self.assertEqual(slug2, 'option-two-main-name-best') |
| 3296 | |
| 3297 | |
3273 | 3298 | |
3274 | 3299 | class SeleniumPrePopulatedChromeTests(SeleniumPrePopulatedFirefoxTests): |
3275 | 3300 | webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver' |