Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T1731 fix together custom donation form #38

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions crowdfunding_compassion/static/src/js/website_widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,67 @@ odoo.define("crowdfunding_compassion.website_widgets", function (require) {
},
});

// Handle donation card selection
publicWidget.registry.CustomAmountSelection = publicWidget.Widget.extend({
selector: "#custom-amount-card",
events: {
click: "_checkCustomCard",
},

start: function () {
this._super.apply(this, arguments);
// Attach click event listener to all card options except custom amount card
const otherCardsInputs = document.querySelectorAll(
'input[name="amount"]:not(#custom-amount-card)'
);
otherCardsInputs.forEach((card) => {
card.addEventListener("click", this._onCardClick.bind(this));
});

// Attach input event listener to custom-amount-field
const customAmountField = document.getElementById("custom-amount-field");
customAmountField.addEventListener("input", this._onInput.bind(this));
},

// Check the custom amount card when custom amount field changes
_onInput: function () {
const customAmountField = document.getElementById("custom-amount-field");

if (customAmountField) {
const amount = customAmountField.value.trim();
const isAmountNotEmpty = amount !== "";

if (isAmountNotEmpty) {
this._checkCustomCard();
}
}
},

// Check the custom amount card and uncheck the others
_checkCustomCard: function () {
const customAmountCard = document.getElementById("custom-amount-card");
const otherCardsInputs = document.querySelectorAll(
'input[name="amount"]:not(#custom-amount-card):not(#custom-amount-field)'
);

if (customAmountCard && otherCardsInputs) {
customAmountCard.checked = true;

otherCardsInputs.forEach((input) => {
input.checked = false;
});
}
},

// Uncheck the custom amount card when any other card option is clicked
_onCardClick: function () {
const customAmountCard = document.getElementById("custom-amount-card");
if (customAmountCard) {
customAmountCard.checked = false;
}
},
});

// EDIT PROJECT FORM
publicWidget.registry.EditProjectForm = publicWidget.Widget.extend({
selector: "#project_update_form",
Expand Down
5 changes: 4 additions & 1 deletion crowdfunding_compassion/templates/project_donation_page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@
<label class="h-100 w-100">
<input
type="radio"
name="amount"
name="amount-card"
value=""
class="card-input-element d-none"
id="custom-amount-card"
Expand All @@ -427,6 +427,9 @@
<input
type="number"
id="custom-amount-field"
name="amount"
t-att-value="amount"
min="1"
/>
<h3
class="text-primary"
Expand Down
Loading