Client side validation

This commit is contained in:
vinchent 2024-08-04 15:06:41 +02:00
parent e30dc5865e
commit c645154836

View File

@ -5,6 +5,7 @@ Virtual Terminal
{{ define "content" }} {{ define "content" }}
<h2 class="mt-3 text-center">Virtual Terminal</h2> <h2 class="mt-3 text-center">Virtual Terminal</h2>
<hr> <hr>
<div class="alert alert-danger text-center d-none" id="card-messages"></div>
<form action="/payment-succecded" <form action="/payment-succecded"
method="post" method="post"
name="charge_form" name="charge_form"
@ -47,10 +48,15 @@ Virtual Terminal
<div class="alert-success text-center" id="card-success" role="alert"></div> <div class="alert-success text-center" id="card-success" role="alert"></div>
</div> </div>
<hr> <hr>
<a href="javastript:void(0)" <a href="javascript:void(0)"
id="pay-button" id="pay-button"
class="btn btn-primary" class="btn btn-primary"
onclick="val()">Charge Card</a> onclick="val()">Charge Card</a>
<div class="text-center d-none" id="processing-payment">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
</form> </form>
{{ end }} {{ end }}
{{ define "js" }} {{ define "js" }}
@ -59,11 +65,22 @@ Virtual Terminal
let card; let card;
let stripe; let stripe;
const cardMessages = document.getElementById("card-messages");
const payButton = document.getElementById("pay-button");
const processing = document.getElementById("processing-payment");
stripe = Stripe(''); // TODO: Publish key to be added stripe = Stripe(''); // TODO: Publish key to be added
function val() { function val() {
let form = document.getElementById("charge_form");
if (form.checkValidity() === false) {
this.event.preventDefault();
this.event.stopPropagation();
form.classList.add("was-validated");
return;
}
form.classList.add("was-validated");
} }
(function () { (function () {