summaryrefslogtreecommitdiff
path: root/website/static/admin/js/prepopulate.js
diff options
context:
space:
mode:
authorprashantsinalkar2019-11-28 11:44:18 +0530
committerprashantsinalkar2019-11-28 11:44:18 +0530
commit06653abddb801782ef2fc9c7bd2ea097fd4c61c6 (patch)
tree31083a2fa059262370e3fb0825ce3e5c2cd0c4f2 /website/static/admin/js/prepopulate.js
parentc43a784c26da8fba39b4d017c1c596587a6255a6 (diff)
downloadpyfoss-06653abddb801782ef2fc9c7bd2ea097fd4c61c6.tar.gz
pyfoss-06653abddb801782ef2fc9c7bd2ea097fd4c61c6.tar.bz2
pyfoss-06653abddb801782ef2fc9c7bd2ea097fd4c61c6.zip
added static files in app
Diffstat (limited to 'website/static/admin/js/prepopulate.js')
-rw-r--r--website/static/admin/js/prepopulate.js34
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);