Skip to content

Commit 035cad9

Browse files
authored
[GOVRACPROD-46] Add warning message and popup for checkbox 'Enable OpenFisca RaC integration' in webform. (#50)
* [GOVRACPROD-46] Add warning message and popup for checkbox 'Enable OpenFisca RaC integration' in webform.
1 parent 841389b commit 035cad9

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

js/openfisca-checkbox-popup.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
(function (Drupal, drupalSettings) {
2+
Drupal.behaviors.openFiscaCheckboxPopup = {
3+
attach: function (context, settings) {
4+
// Ensure we only attach once per context.
5+
const checkboxes = context.querySelectorAll(
6+
'input[name="third_party_settings[webform_openfisca][fisca_enabled]"]'
7+
);
8+
9+
checkboxes.forEach(function (checkbox) {
10+
if (!checkbox.dataset.popupAttached) {
11+
checkbox.dataset.popupAttached = true;
12+
13+
checkbox.addEventListener('change', function () {
14+
if (checkbox.checked) {
15+
Drupal.dialog(
16+
'<p>Please make sure that you have disabled saving of submissions for this form.</p>',
17+
{
18+
title: 'Important Notice',
19+
width: 400
20+
}
21+
).showModal();
22+
}
23+
});
24+
}
25+
});
26+
}
27+
};
28+
})(Drupal, drupalSettings);

src/WebformThirdPartySettingsFormAlter.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ public function alterForm(array &$form, FormStateInterface $form_state): void {
155155
'#default_value' => $openfisca_settings->hasImmediateResponseAjaxIndicator(),
156156
'#weight' => 20,
157157
];
158+
158159
$form['#validate'][] = [$this, 'validateForm'];
160+
161+
// Add popup for fisca_enabled checkbox.
162+
$form['#attached']['library'][] = 'webform_openfisca/openfisca-checkbox-popup';
159163
}
160164

161165
/**
@@ -174,6 +178,13 @@ public function validateForm(array $form, FormStateInterface $form_state): void
174178
// @codeCoverageIgnoreEnd
175179
}
176180

181+
$enabled = $form_state->getValue(['third_party_settings', 'webform_openfisca', 'fisca_enabled']);
182+
if ($enabled) {
183+
$this->messenger->addWarning(
184+
$this->t('Please make sure that you have disabled saving of submissions for this form.')
185+
);
186+
}
187+
177188
$fisca_endpoint = $form_state->getValue(
178189
['third_party_settings', 'webform_openfisca', 'fisca_api_endpoint']
179190
) ?: '';

webform_openfisca.libraries.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ immediate_response:
55
- core/drupal
66
- core/jquery
77
- core/once
8+
9+
openfisca-checkbox-popup:
10+
js:
11+
js/openfisca-checkbox-popup.js: {}
12+
dependencies:
13+
- core/drupal.dialog

0 commit comments

Comments
 (0)