diff options
author | Prashant S | 2019-11-28 12:10:16 +0530 |
---|---|---|
committer | GitHub | 2019-11-28 12:10:16 +0530 |
commit | 10a937a8ed33d4b4f6e89bcb4648310e87724dea (patch) | |
tree | 3c75073273e6ae6cc2f986dbdb592ddd23dac62b /website/static/admin/js/prepopulate.js | |
parent | 9d63c1b8d18d29702712b19cb338913fe5a864fc (diff) | |
parent | 2a52d173d596281e871b1686dd1ceb800cafe122 (diff) | |
download | pyfoss-10a937a8ed33d4b4f6e89bcb4648310e87724dea.tar.gz pyfoss-10a937a8ed33d4b4f6e89bcb4648310e87724dea.tar.bz2 pyfoss-10a937a8ed33d4b4f6e89bcb4648310e87724dea.zip |
Merge pull request #11 from prashantsinalkar/master
updated the django version 2.2.7 LTS and packages to latest version
Diffstat (limited to 'website/static/admin/js/prepopulate.js')
-rw-r--r-- | website/static/admin/js/prepopulate.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/website/static/admin/js/prepopulate.js b/website/static/admin/js/prepopulate.js new file mode 100644 index 0000000..24f24f9 --- /dev/null +++ b/website/static/admin/js/prepopulate.js @@ -0,0 +1,34 @@ +(function($) { + $.fn.prepopulate = function(dependencies, maxLength) { + /* + Depends on urlify.js + Populates a selected field with the values of the dependent fields, + URLifies and shortens the string. + dependencies - array of dependent fields id's + maxLength - maximum length of the URLify'd string + */ + return this.each(function() { + var field = $(this); + + field.data('_changed', false); + field.change(function() { + field.data('_changed', true); + }); + + var populate = function () { + // Bail if the fields value has changed + if (field.data('_changed') == true) return; + + var values = []; + $.each(dependencies, function(i, field) { + if ($(field).val().length > 0) { + values.push($(field).val()); + } + }) + field.val(URLify(values.join(' '), maxLength)); + }; + + $(dependencies.join(',')).keyup(populate).change(populate).focus(populate); + }); + }; +})(django.jQuery); |