Skip to content

Commit

Permalink
work through js as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Barny-Thorpe committed Mar 20, 2024
1 parent caeb89c commit d46cfc9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
17 changes: 16 additions & 1 deletion public/js/gf-giftaid-field-frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,24 @@
*/

document.addEventListener('DOMContentLoaded', () => {
window.gform.addAction('gform_input_change', updateGFFromTotal, 10);
determineDonationTotalMethod();
});

function determineDonationTotalMethod() {
const giftAidComponent = document.querySelector('.gift-box-wrapper');
if (! (giftAidComponent instanceof HTMLElement)) {
return;
}
const donationTotalInput = giftAidComponent.querySelector('input.donation-total-select');
if (!(donationTotalInput instanceof HTMLInputElement)) {
return;
}
const donationTotalSelection = donationTotalInput.value;
if ("ginput_total" === donationTotalSelection) {
window.gform.addAction('gform_input_change', updateGFFromTotal, 10);
}
}

function updateGFFromTotal(elem) {
const total = getTotalAmount(elem);
if (! total || !total.donation || !total.giftAidTotal) {
Expand Down
9 changes: 7 additions & 2 deletions src/GiftAidField.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,22 @@ public function get_field_input($form, $value = '', $entry = null): string
{
$id = (int) $this->id;
$giftaidImage = plugins_url('public/img/giftaid.svg', __DIR__);
$donationTotalSelect = $this->donationTotalSelect ?? 'query_parameter';

ob_start();
?>
<div class="gift-box-wrapper bg-gray-50 rounded-br-4 p-7.5">
<input title="Donation Total Select Value" class="donation-total-select" type="text" value="<?php echo esc_attr($donationTotalSelect); ?>" disabled hidden>

<div class="giftaid-logo mb-2">
<img src="<?php echo esc_url($giftaidImage); ?>" alt="GiftAid logo">
</div>

<div class="description text-primary font-medium text-xl mb-2">
<?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
<?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php echo wpautop(wp_kses_post($this->get_calculated_gift())); ?>
</div>

<div class="gift-box-form-wrapper my-6 pb-6 border-b border-b-gray-200">
<div class="ginput_container ginput_container_checkbox mb-6">
<div class="gfield_checkbox" id="input_<?php echo esc_attr($id); ?>">
Expand All @@ -90,6 +94,7 @@ public function get_field_input($form, $value = '', $entry = null): string
</div>
</div>
</div>

<div class="details-description"><?php echo wp_kses_post($this->description); ?></div>
</div>
<?php
Expand Down

0 comments on commit d46cfc9

Please sign in to comment.