Sha256: 989e6057cfe0a61dbf48ba3ee0e5035455c42e83bc3d0bdc2d5dcd0a43ba1db6

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

// Configure constants

//// Response URL
const response = new URL(window.location.href).searchParams.has("response");

//// Email
const user = {{ site.formspree.contact-form.email.user }};
const company = {{ site.formspree.contact-form.email.company }};
const global_domain = {{ site.formspree.contact-form.email.global_domain }};

// Hide elements as needed
document.getElementById(response ? 'contact-form' : 'form-response').classList.add("d-none");
document.getElementById(response ? '{{ page.form.id }}' : 'form-response').classList.add("d-none")

// Define form action
document.querySelector('#contact-form').setAttribute('action', 'https://formspree.io/' + user + '@' + company + '.' + global_domain);

// Disable form submission if there are invalid fields
(function() {
  'use strict';
  window.addEventListener('load', function() {
    // Fetch all the forms we want to apply custom Bootstrap validation styles to
    var forms = document.getElementsByClassName('needs-validation');
    // Loop over them and prevent submission
    var validation = Array.prototype.filter.call(forms, function(form) {
      form.addEventListener('submit', function(event) {
        if (form.checkValidity() === false) {
          event.preventDefault();
          event.stopPropagation();
        }
        form.classList.add('was-validated');
      }, false);
    });
  }, false);
})();

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jekyll-theme-marketing-1.0.1 _includes/components/forms/formspree.js
jekyll-theme-marketing-1.0.0 _includes/components/forms/formspree.js