Skip to content

Commit

Permalink
HDX-10024 preselect values and disable submit button
Browse files Browse the repository at this point in the history
  • Loading branch information
ccataalin committed Aug 2, 2024
1 parent b99e97d commit 0575340
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
$(document).ready(function () {
var $form = $('#mc_embed_signup form');
var DATASETS_GROUP = '[4389]';
var $button = $form.find('#mc-embedded-subscribe');

var DATASETS_GROUPS = [
'[4389]'
];
var LOCATIONS_GROUPS = [
'[4397]',
'[4405]',
'[4417]',
'[4409]',
'[4401]',
'[4421]',
'[4425]'
];
var DATASETS_LOCATIONS_GROUPS = DATASETS_GROUPS.concat(LOCATIONS_GROUPS);

var ALL_LOCATIONS = [
'[4397][16384]',
'[4405][8388608]',
Expand Down Expand Up @@ -38,24 +53,32 @@ $(document).ready(function () {
'[4421][8]',
];

function select_group(group) {
$form.find('input[name^="group' + group + '"]').prop('checked', true);
function select_groups(groups) {
groups.forEach(function (group) {
$form.find('input[name^="group' + group + '"]').prop('checked', true);
});
disable_submit_button();
}

function unselect_group(group) {
$form.find('input[name^="group' + group + '"]').prop('checked', false);
function unselect_group(groups) {
groups.forEach(function (group) {
$form.find('input[name^="group' + group + '"]').prop('checked', false);
});
disable_submit_button();
}

function select_values(values) {
values.forEach(function (value) {
$form.find('input[name="group' + value + '"]').prop('checked', true);
});
disable_submit_button();
}

function unselect_values(values) {
values.forEach(function (value) {
$form.find('input[name="group' + value + '"]').prop('checked', false);
});
disable_submit_button();
}

function add_select_buttons(group_label, group) {
Expand All @@ -66,15 +89,32 @@ $(document).ready(function () {
group_label.append(unselect_btn);

select_btn.click(function () {
select_group(group);
select_groups([group]);
});
unselect_btn.click(function () {
unselect_group(group);
unselect_group([group]);
});
}

function disable_submit_button() {
var dataset_checked = DATASETS_GROUPS.some(function (group) {
return $form.find('input[name^="group' + group + '"]:checked').length > 0;
});

var location_checked = LOCATIONS_GROUPS.some(function (group) {
return $form.find('input[name^="group' + group + '"]:checked').length > 0;
});

if(dataset_checked && location_checked) {
$button.removeClass('disabled').removeAttr('disabled');
}
else {
$button.addClass('disabled').attr('disabled', 'disabled');
}
}

$form.find('#select-all-datasets').on('click', function () {
select_group(DATASETS_GROUP);
select_groups(DATASETS_GROUPS);
});
$form.find('#select-all-locations').on('click', function () {
select_values(ALL_LOCATIONS);
Expand All @@ -97,4 +137,9 @@ $(document).ready(function () {
}
});

DATASETS_LOCATIONS_GROUPS.forEach(function (group) {
$form.find('input[name^="group' + group + '"]').on('change', function () {
disable_submit_button();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,37 @@
<ul class="list-unstyled">
<li class="form-check">
<input type="checkbox" name="group[4389][128]" class="form-check-input"
id="mce-group[4389]-4389-0" value="">
id="mce-group[4389]-4389-0" value="" checked>
<label class="form-check-label" for="mce-group[4389]-4389-0">Conflict-driven
displacement - IDMC</label>
</li>
<li class="form-check">
<input type="checkbox" name="group[4389][256]" class="form-check-input"
id="mce-group[4389]-4389-1" value="">
id="mce-group[4389]-4389-1" value="" checked>
<label class="form-check-label" for="mce-group[4389]-4389-1">Disaster-driven
displacement - IDMC</label>
</li>
<li class="form-check">
<input type="checkbox" name="group[4389][1024]" class="form-check-input"
id="mce-group[4389]-4389-2" value="">
id="mce-group[4389]-4389-2" value="" checked>
<label class="form-check-label" for="mce-group[4389]-4389-2">Armed conflict -
ACLED</label>
</li>
<li class="form-check">
<input type="checkbox" name="group[4389][2048]" class="form-check-input"
id="mce-group[4389]-4389-3" value="">
id="mce-group[4389]-4389-3" value="" checked>
<label class="form-check-label" for="mce-group[4389]-4389-3">Food insecurity -
IPC/CH</label>
</li>
<li class="form-check">
<input type="checkbox" name="group[4389][4096]" class="form-check-input"
id="mce-group[4389]-4389-4" value="">
id="mce-group[4389]-4389-4" value="" checked>
<label class="form-check-label" for="mce-group[4389]-4389-4">Agricultural hotspots
- JRC ASAP</label>
</li>
<li class="form-check">
<input type="checkbox" name="group[4389][8192]" class="form-check-input"
id="mce-group[4389]-4389-5" value="">
id="mce-group[4389]-4389-5" value="" checked>
<label class="form-check-label" for="mce-group[4389]-4389-5">Market monitoring -
WFP</label>
</li>
Expand All @@ -123,7 +123,7 @@
<ul class="list-unstyled">
<li class="form-check">
<input type="checkbox" name="group[4397][16384]" class="form-check-input"
id="mce-group[4397]-4397-0" value="">
id="mce-group[4397]-4397-0" value="" checked>
<label class="form-check-label" for="mce-group[4397]-4397-0">All locations in the
region</label>
</li>
Expand All @@ -147,7 +147,7 @@
<ul class="list-unstyled">
<li class="form-check">
<input type="checkbox" name="group[4405][8388608]" class="form-check-input"
id="mce-group[4405]-4405-0" value="">
id="mce-group[4405]-4405-0" value="" checked>
<label class="form-check-label" for="mce-group[4405]-4405-0">All locations in the
region</label>
</li>
Expand All @@ -166,7 +166,7 @@
<ul class="list-unstyled">
<li class="form-check">
<input type="checkbox" name="group[4417][8589934592]" class="form-check-input"
id="mce-group[4417]-4417-0" value="">
id="mce-group[4417]-4417-0" value="" checked>
<label class="form-check-label" for="mce-group[4417]-4417-0">All locations in the
region</label>
</li>
Expand Down Expand Up @@ -211,7 +211,7 @@
<ul class="list-unstyled">
<li class="form-check">
<input type="checkbox" name="group[4409][33554432]" class="form-check-input"
id="mce-group[4409]-4409-0" value="">
id="mce-group[4409]-4409-0" value="" checked>
<label class="form-check-label" for="mce-group[4409]-4409-0">All locations in the
region</label>
</li>
Expand Down Expand Up @@ -242,7 +242,7 @@
<ul class="list-unstyled">
<li class="form-check">
<input type="checkbox" name="group[4401][65536]" class="form-check-input"
id="mce-group[4401]-4401-0" value="">
id="mce-group[4401]-4401-0" value="" checked>
<label class="form-check-label" for="mce-group[4401]-4401-0">All locations in the
region</label>
</li>
Expand Down Expand Up @@ -281,7 +281,7 @@
<ul class="list-unstyled">
<li class="form-check">
<input type="checkbox" name="group[4421][549755813888]" class="form-check-input"
id="mce-group[4421]-4421-0" value="">
id="mce-group[4421]-4421-0" value="" checked>
<label class="form-check-label" for="mce-group[4421]-4421-0">All locations in the
region</label>
</li>
Expand Down Expand Up @@ -337,7 +337,7 @@
<ul class="list-unstyled">
<li class="form-check">
<input type="checkbox" name="group[4425][16]" class="form-check-input"
id="mce-group[4425]-4425-0" value="">
id="mce-group[4425]-4425-0" value="" checked>
<label class="form-check-label" for="mce-group[4425]-4425-0">All locations in the
region</label>
</li>
Expand Down

0 comments on commit 0575340

Please sign in to comment.