Files
nairobi/app/assets/javascripts/advanced_search.js
Javi Martín 08c410cc93 Make target filter change when goal filter changes
Note we're using both the `hidden` and `disabled` properties to
guarantee compatibility with user agents which might still display the
option even when using the `hidden` attribute or hiding it with
`display: none`. We could also use `hide()` and `show()` instead of the
`hidden` property, but since we're using the `disabled` property, I
thought the code would be easier to read if we used properties in both
cases.

Also note users will no longer be able to get, let's say, debates which
are related to goal 1 and target 2.1. We think this use case is highly
unlikely and there's no need to take it into account.
2021-01-28 18:54:04 +01:00

40 lines
1.2 KiB
JavaScript

(function() {
"use strict";
App.AdvancedSearch = {
advanced_search_terms: function() {
return $("#js-advanced-search").data("advanced-search-terms");
},
toggle_form: function(event) {
event.preventDefault();
$("#js-advanced-search").slideToggle();
},
toggle_date_options: function() {
if ($("#js-advanced-search-date-min").val() === "custom") {
$("#js-custom-date").show();
$(".js-calendar").datepicker("option", "disabled", false);
} else {
$("#js-custom-date").hide();
$(".js-calendar").datepicker("option", "disabled", true);
}
},
initialize: function() {
if (App.AdvancedSearch.advanced_search_terms()) {
$("#js-advanced-search").show();
App.AdvancedSearch.toggle_date_options();
}
$("#js-advanced-search-title").on({
click: function(event) {
App.AdvancedSearch.toggle_form(event);
}
});
$("#js-advanced-search-date-min").on({
change: function() {
App.AdvancedSearch.toggle_date_options();
}
});
App.SDGSyncGoalAndTargetFilters.sync($("#advanced_search_form"));
}
};
}).call(this);