Changeset View
Changeset View
Standalone View
Standalone View
templates/checkout/checkout.html
| Show All 17 Lines | function do_recaptcha(event) { | ||||
| let recaptcha_elt = _get_recaptcha_element(); | let recaptcha_elt = _get_recaptcha_element(); | ||||
| if (recaptcha_elt.textContent) { | if (recaptcha_elt.textContent) { | ||||
| callback_recaptcha_ok(recaptcha_elt.textContent); | callback_recaptcha_ok(recaptcha_elt.textContent); | ||||
| return; | return; | ||||
| } | } | ||||
| grecaptcha.execute(); | grecaptcha.execute(); | ||||
| } | } | ||||
| function _get_helptext(el) { | |||||
| let helptext = el.nextElementSibling; | |||||
| if (!helptext || !helptext.classList.contains('helptext')) { | |||||
| return null; | |||||
| } | |||||
| return helptext; | |||||
| } | |||||
| function _foreach_required(form, func) { | |||||
| var elems = form.querySelectorAll("input,textarea,select"); | |||||
| for (var i = 0; i < elems.length; i++) { | |||||
| let el = elems[i]; | |||||
| if (el.type == 'hidden' || !el.required) { | |||||
| continue; | |||||
| } | |||||
| let helptext = _get_helptext(el); | |||||
| func(el, helptext); | |||||
| } | |||||
| } | |||||
| function handle_form_validation(form) { | |||||
| // requestSubmit and HTML5 form validation are not supported in Safari WebKit (and IE). | |||||
| // The form has to be validated and required fields have to be hightlighted. | |||||
| if (!form.checkValidity()) { | |||||
| // The form is invalid, highlight help texts under required fields | |||||
| _foreach_required(form, function(el, helptext) { | |||||
| if (!el.required || el.validity.valid || !helptext) { | |||||
| return; | |||||
| } | |||||
| helptext.classList.add("text-danger"); | |||||
| }); | |||||
| } else { | |||||
| // The form is valid, no need to highlight help texts under required fields | |||||
| _foreach_required(form, function(el, helptext) { | |||||
| if (helptext) { | |||||
| helptext.classList.remove("text-danger"); | |||||
| } | |||||
| }); | |||||
| // Proceed to submit the form | |||||
| const event = new Event("submit"); | |||||
| form.dispatchEvent(event); | |||||
| } | |||||
| } | |||||
| /* Called by the reCAPTCHA v2 API after a successful verification. */ | /* Called by the reCAPTCHA v2 API after a successful verification. */ | ||||
| function callback_recaptcha_ok(token) { | function callback_recaptcha_ok(token) { | ||||
| let recaptcha_elt = _get_recaptcha_element(); | let recaptcha_elt = _get_recaptcha_element(); | ||||
| recaptcha_elt.textContent = token; | recaptcha_elt.textContent = token; | ||||
| document.getElementById("payment-form").requestSubmit(); | let form = document.getElementById("payment-form"); | ||||
| if (form.requestSubmit) { | |||||
| form.requestSubmit(); | |||||
| } else { | |||||
| handle_form_validation(form); | |||||
| } | |||||
| } | } | ||||
| </script>{% endblock %} | </script>{% endblock %} | ||||
| {% block after_header %} | {% block after_header %} | ||||
| <form class="checkout-form pt-3" id="payment-form" method="post">{% csrf_token %} | <form class="checkout-form pt-3" id="payment-form" method="post">{% csrf_token %} | ||||
| <section class="checkout-form-fields"> | <section class="checkout-form-fields"> | ||||
| <ul class="form">{{ form.as_ul }}</ul> | <ul class="form">{{ form.as_ul }}</ul> | ||||
| <div id="gateway-errors"></div> | <div id="gateway-errors"></div> | ||||
| </section> | </section> | ||||
| ▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines | |||||