@hortonstudio/main 1.7.12 → 1.7.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/autoInit/form.js CHANGED
@@ -478,14 +478,31 @@ export function init() {
478
478
  const customValidateField = (field) => {
479
479
  const value = field.value.trim();
480
480
  const type = field.type || field.tagName.toLowerCase();
481
-
481
+
482
482
  // Check if field was required (now stored in data-was-required)
483
483
  if (field.hasAttribute('data-was-required')) {
484
- // Special handling for checkboxes and radio buttons
485
- if (type === 'checkbox' || type === 'radio') {
484
+ // Special handling for checkboxes
485
+ if (type === 'checkbox') {
486
486
  return field.checked;
487
487
  }
488
-
488
+
489
+ // Special handling for radio buttons - check if ANY radio in the group is checked
490
+ if (type === 'radio') {
491
+ const radioName = field.getAttribute('name');
492
+ if (radioName) {
493
+ // Find all radios with the same name in the same form
494
+ const form = field.closest('form');
495
+ const radioGroup = form ?
496
+ form.querySelectorAll(`input[type="radio"][name="${radioName}"]`) :
497
+ document.querySelectorAll(`input[type="radio"][name="${radioName}"]`);
498
+
499
+ // Check if any radio in the group is checked
500
+ return Array.from(radioGroup).some(radio => radio.checked);
501
+ }
502
+ // Fallback to individual check if no name attribute
503
+ return field.checked;
504
+ }
505
+
489
506
  // For other field types, check if empty
490
507
  if (!value) {
491
508
  return false;
@@ -544,13 +561,27 @@ export function init() {
544
561
  const requiredFields = container.querySelectorAll('input[data-was-required], textarea[data-was-required], select[data-was-required]');
545
562
  let isValid = true;
546
563
  let firstInvalidField = null;
564
+ const validatedRadioGroups = new Set(); // Track validated radio groups
547
565
 
548
566
  requiredFields.forEach((field) => {
567
+ const type = field.type || field.tagName.toLowerCase();
568
+
569
+ // For radio buttons, only validate once per group
570
+ if (type === 'radio') {
571
+ const radioName = field.getAttribute('name');
572
+ if (radioName && validatedRadioGroups.has(radioName)) {
573
+ return; // Skip - already validated this radio group
574
+ }
575
+ if (radioName) {
576
+ validatedRadioGroups.add(radioName);
577
+ }
578
+ }
579
+
549
580
  const fieldValid = customValidateField(field);
550
-
581
+
551
582
  if (!fieldValid) {
552
583
  isValid = false;
553
-
584
+
554
585
  if (!firstInvalidField) {
555
586
  firstInvalidField = field;
556
587
  }
@@ -561,9 +592,9 @@ export function init() {
561
592
  activeErrors.forEach((_, input) => {
562
593
  removeError(input);
563
594
  });
564
-
595
+
565
596
  firstInvalidField.focus();
566
-
597
+
567
598
  const message = getErrorMessage(firstInvalidField);
568
599
  showError(firstInvalidField, message);
569
600
  }
@@ -650,29 +681,7 @@ export function init() {
650
681
  if (finalAnimElement) {
651
682
  finalAnimElement.click();
652
683
  }
653
-
654
- // Store redirect URL for after successful submission
655
- if (formWrapper && formWrapper.hasAttribute('data-hs-form-redirect')) {
656
- const redirectUrl = formWrapper.getAttribute('data-hs-form-redirect');
657
-
658
- if (redirectUrl && redirectUrl.trim()) {
659
- // Set up redirect after form submission completes
660
- const handleFormSubmissionComplete = () => {
661
- // Minimal delay to ensure form submission is processed
662
- setTimeout(() => {
663
- try {
664
- window.location.href = redirectUrl.trim();
665
- } catch (error) {
666
- console.error('Form redirect failed:', error);
667
- }
668
- }, 1);
669
- };
670
-
671
- // Listen for when the form submission completes
672
- form.addEventListener('submit', handleFormSubmissionComplete, { once: true });
673
- }
674
- }
675
-
684
+
676
685
  // Prevent submission if configured to do so
677
686
  if (shouldPreventSubmit) {
678
687
  event.preventDefault();
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // Version:1.7.12
1
+ // Version:1.7.13
2
2
  const API_NAME = "hsmain";
3
3
 
4
4
  const initializeHsMain = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hortonstudio/main",
3
- "version": "1.7.12",
3
+ "version": "1.7.13",
4
4
  "description": "Animation and utility library for client websites",
5
5
  "main": "index.js",
6
6
  "type": "module",