Skip to content

Commit

Permalink
Initial pass at styling the donation form
Browse files Browse the repository at this point in the history
This includes some JS to manipulate the form elements. css will be added via the customizer for now. The added JS will likely load too early, but at least it's there to be called.
  • Loading branch information
nickpagz committed May 22, 2024
1 parent 3178b43 commit 6d93c3b
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 4 deletions.
2 changes: 1 addition & 1 deletion themes/osi/assets/js/build/theme.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '1a77530059955fb6eaa5');
<?php return array('dependencies' => array(), 'version' => 'ee5da5bfafd11f296b5b');
2 changes: 1 addition & 1 deletion themes/osi/assets/js/build/theme.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion themes/osi/assets/js/build/vendor.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('jquery'), 'version' => 'e025ea38feca3ffa8690');
<?php return array('dependencies' => array('jquery'), 'version' => '9a08034ec8a2505dbde0');
2 changes: 1 addition & 1 deletion themes/osi/assets/js/build/vendor.js

Large diffs are not rendered by default.

75 changes: 75 additions & 0 deletions themes/osi/assets/js/src/theme/donation-form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('remoteForm-form-ContributionPage7');
const firstName = document.getElementById('first_name').closest('.form-group');
const lastName = document.getElementById('last_name').closest('.form-group');
const email = document.getElementById('email-primary').closest('.form-group');
const creditCardNumber = document.getElementById('credit_card_number').closest('.form-group');
const cvv = document.getElementById('cvv2').closest('.form-group');
const expMonth = document.getElementById('credit_card_exp_date_M').closest('.form-group');
const expYear = document.getElementById('credit_card_exp_date_Y').closest('.form-group');
const submitButton = document.getElementById('remoteform-submit');
const amountSection = document.querySelector('label.rf-label').parentNode;
const radioInputs = document.querySelectorAll('.form-check-input:not([value="54"])'); // Exclude the OSI membership checkbox

// Create new div for grid layout and set it up for CSS Grid
const gridContainer = document.createElement('div');
gridContainer.className = 'form-check-grid';
amountSection.parentNode.insertBefore(gridContainer, amountSection);

// Move only the radio buttons into the grid container
radioInputs.forEach(radio => {
gridContainer.appendChild(radio.parentNode);
});

// Create new div and append input fields
const newDiv = document.createElement('div');
newDiv.style.display = 'none'; // Initially hidden
newDiv.append(firstName, lastName, email, creditCardNumber, cvv, expMonth, expYear, submitButton);
form.insertBefore(newDiv, amountSection.nextSibling);

// Modify amounts display
document.querySelectorAll('.form-check-label').forEach(label => {
label.textContent = label.textContent.replace(/ - \$[\d\.]+/, '');
});

// Change last radio to checkbox
const memberRadio = document.querySelector('input[value="54"]');
if (memberRadio) { // Check if element exists before changing
memberRadio.type = 'checkbox';
memberRadio.closest('.form-check').querySelector('label').textContent = 'Yes, I want to become an OSI member!';
newDiv.prepend(memberRadio.closest('.form-check'));
}

// Handle button click interactions
radioInputs.forEach(radio => {
const label = radio.nextElementSibling; // Assuming label immediately follows input
label.addEventListener('click', function() {
// Uncheck all other radios
radioInputs.forEach(otherRadio => {
if (otherRadio !== radio) {
otherRadio.checked = false;
}
});
// Check this radio
radio.checked = true;
// Manually trigger the 'change' event if necessary
radio.dispatchEvent(new Event('change'));
});
});

// Add Donate button
const donateButton = document.createElement('button');
donateButton.textContent = 'Contribute';
donateButton.type = 'button';
donateButton.addEventListener('click', () => {
if (newDiv.style.display === 'none') {
newDiv.style.display = 'block';
donateButton.textContent = 'Cancel';
newDiv.style.transition = 'all 0.3s ease';
} else {
newDiv.style.display = 'none';
donateButton.textContent = 'Contribute';
}
});
form.appendChild(donateButton);
});
1 change: 1 addition & 0 deletions themes/osi/assets/js/src/theme/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ import './sidebar-nav.js';
import './skip-link-focus-fix.js';
import './search-toggle.js';
import './license-header-wrap.js';
import './donation-form.js';

0 comments on commit 6d93c3b

Please sign in to comment.