travel grant fields in registration (germany only)
[prawokultury.git] / prawokultury / static / js / optional_fields.js
diff --git a/prawokultury/static/js/optional_fields.js b/prawokultury/static/js/optional_fields.js
new file mode 100644 (file)
index 0000000..cfbae0e
--- /dev/null
@@ -0,0 +1,22 @@
+/* globals travelGrantCountries */
+
+$(document).ready(function() {
+
+    var countrySelect = $('#id_country');
+    var grantCheckbox = $('#id_travel_grant');
+    countrySelect.on('change', function () {
+        var goodCountry = $.inArray($(this).val(), travelGrantCountries) > -1;
+        grantCheckbox.closest('tr').toggle(goodCountry);
+        if (!goodCountry) {
+            grantCheckbox.prop('checked', false);
+            grantCheckbox.trigger('change');
+        }
+    });
+    grantCheckbox.on('change', function () {
+        var checked = Boolean(this.checked);
+        $('#id_travel_grant_motivation').closest('tr').toggle(checked);
+    });
+    countrySelect.trigger('change');
+    grantCheckbox.trigger('change');
+
+});