Skip to content

Commit fddf777

Browse files
committed
donation-form tweaks
1 parent e398954 commit fddf777

1 file changed

Lines changed: 33 additions & 12 deletions

File tree

themes/osi/assets/js/src/theme/donation-form.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
function waitForElement(selector, callback) {
2-
if (document.querySelector(selector)) {
3-
callback();
4-
} else {
5-
setTimeout(function() {
6-
waitForElement(selector, callback);
7-
}, 100);
8-
}
9-
}
1+
function osiFormInit(id) {
2+
const formId = id.id;
3+
/*if (formId !== 17) {
4+
console.error("Form ID is not 17. This script is only for form ID 17.");
5+
return;
6+
}*/
107

11-
waitForElement("#remoteForm-form-ContributionPage7", function() {
12-
const form = document.getElementById('remoteForm-form-ContributionPage7');
8+
const form = document.getElementById('remoteForm-form-ContributionPage' + formId);
139
const firstName = document.getElementById('first_name').closest('.form-group');
1410
const lastName = document.getElementById('last_name').closest('.form-group');
1511
const email = document.getElementById('email-primary').closest('.form-group');
@@ -20,6 +16,7 @@ waitForElement("#remoteForm-form-ContributionPage7", function() {
2016
const submitButton = document.getElementById('remoteform-submit');
2117
const amountSection = document.querySelector('label.rf-label').parentNode;
2218
const radioInputs = document.querySelectorAll('.form-check-input:not([value="54"])'); // Exclude the OSI membership checkbox
19+
const alert = document.querySelector('.alert-warning');
2320

2421
// Create new div for grid layout and set it up for CSS Grid
2522
const gridContainer = document.createElement('div');
@@ -35,6 +32,9 @@ waitForElement("#remoteForm-form-ContributionPage7", function() {
3532
const newDiv = document.createElement('div');
3633
newDiv.style.display = 'none'; // Initially hidden
3734
newDiv.append(firstName, lastName, email, creditCardNumber, cvv, expMonth, expYear, submitButton);
35+
if (alert) {
36+
newDiv.appendChild(alert);
37+
}
3838
form.insertBefore(newDiv, amountSection.nextSibling);
3939

4040
// Modify amounts display
@@ -82,4 +82,25 @@ waitForElement("#remoteForm-form-ContributionPage7", function() {
8282
}
8383
});
8484
form.appendChild(donateButton);
85-
});
85+
}
86+
87+
function customFieldCreation(key, def, type, createFieldFunc, wrapFieldFunc) {
88+
var field = createFieldFunc(key, def, type);
89+
if (field === null) {
90+
return null;
91+
}
92+
93+
if (key === 'credit_card_number' || key === 'cvv2' || key === 'credit_card_exp_date_M' || key === 'credit_card_exp_date_Y') {
94+
// return null;
95+
}
96+
97+
98+
99+
return wrapFieldFunc(key, def, field);
100+
}
101+
102+
function customSubmitData(data) {
103+
// Display the data that will be submitted
104+
console.log(data);
105+
return data;
106+
}

0 commit comments

Comments
 (0)