Disable phase date fields when a phase is disabled
The JavaScript involved wasn't working since we removed the disable-date
attribute in commit 73ff6881.
We're also improving the JavaScript in two ways:
First, we trigger the `change` event immediately, so when the page loads
date fields are disabled when phases are disabled.
And second, we don't remove the selected dates when disabling a phase,
so disabling it and enabling it again will keep the selected values.
This commit is contained in:
@@ -2,21 +2,21 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
App.LegislationAdmin = {
|
App.LegislationAdmin = {
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
$("input[type='checkbox'][data-disable-date]").on({
|
$(".legislation-process-form").find("[name$='enabled]'],[name$='[published]']").on({
|
||||||
change: function() {
|
change: function() {
|
||||||
var checkbox, date_selector, parent;
|
var checkbox;
|
||||||
checkbox = $(this);
|
checkbox = $(this);
|
||||||
parent = $(this).parents(".row:eq(0)");
|
|
||||||
date_selector = $(this).data("disable-date");
|
checkbox.closest("fieldset").find("input[type='text']").each(function() {
|
||||||
parent.find("input[type='text'][id^='" + date_selector + "']").each(function() {
|
|
||||||
if (checkbox.is(":checked")) {
|
if (checkbox.is(":checked")) {
|
||||||
$(this).removeAttr("disabled");
|
$(this).removeAttr("disabled");
|
||||||
} else {
|
} else {
|
||||||
$(this).val("");
|
$(this).prop("disabled", true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}).trigger("change");
|
||||||
|
|
||||||
$("#nested_question_options").on("cocoon:after-insert", function() {
|
$("#nested_question_options").on("cocoon:after-insert", function() {
|
||||||
App.Globalize.refresh_visible_translations();
|
App.Globalize.refresh_visible_translations();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1074,6 +1074,10 @@ form {
|
|||||||
&.error {
|
&.error {
|
||||||
margin-bottom: rem-calc(1);
|
margin-bottom: rem-calc(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
background-color: $input-background-disabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[type="checkbox"] + label,
|
[type="checkbox"] + label,
|
||||||
|
|||||||
@@ -240,6 +240,44 @@ describe "Admin collaborative legislation" do
|
|||||||
expect(page).not_to have_content "Draft publication"
|
expect(page).not_to have_content "Draft publication"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Enabling/disabling a phase enables/disables its date fields", :js do
|
||||||
|
process.update!(published: false)
|
||||||
|
|
||||||
|
visit edit_admin_legislation_process_path(process)
|
||||||
|
|
||||||
|
expect(page).to have_field "start_date", disabled: true
|
||||||
|
expect(page).to have_field "end_date", disabled: true
|
||||||
|
|
||||||
|
check "legislation_process[published]"
|
||||||
|
fill_in "start_date", with: "07/07/2007"
|
||||||
|
fill_in "end_date", with: "08/08/2008"
|
||||||
|
uncheck "legislation_process[published]"
|
||||||
|
|
||||||
|
expect(page).to have_field "start_date", disabled: true
|
||||||
|
expect(page).to have_field "end_date", disabled: true
|
||||||
|
|
||||||
|
check "legislation_process[published]"
|
||||||
|
|
||||||
|
expect(page).to have_field "start_date", disabled: false, with: "07/07/2007"
|
||||||
|
expect(page).to have_field "end_date", disabled: false, with: "08/08/2008"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Enabling/disabling a phase does not enable/disable another phase date fields", :js do
|
||||||
|
process.update!(draft_phase_enabled: false, draft_publication_enabled: false)
|
||||||
|
|
||||||
|
visit edit_admin_legislation_process_path(process)
|
||||||
|
|
||||||
|
expect(page).to have_field "draft_start_date", disabled: true
|
||||||
|
expect(page).to have_field "draft_end_date", disabled: true
|
||||||
|
expect(page).to have_field "draft_publication_date", disabled: true
|
||||||
|
|
||||||
|
check "legislation_process[draft_phase_enabled]"
|
||||||
|
|
||||||
|
expect(page).to have_field "draft_start_date", disabled: false
|
||||||
|
expect(page).to have_field "draft_end_date", disabled: false
|
||||||
|
expect(page).to have_field "draft_publication_date", disabled: true
|
||||||
|
end
|
||||||
|
|
||||||
scenario "Change proposal categories" do
|
scenario "Change proposal categories" do
|
||||||
visit edit_admin_legislation_process_path(process)
|
visit edit_admin_legislation_process_path(process)
|
||||||
within(".admin-content") { click_link "Proposals" }
|
within(".admin-content") { click_link "Proposals" }
|
||||||
|
|||||||
Reference in New Issue
Block a user