Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Call for Promos #157

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 74 additions & 32 deletions _includes/promos/10tvpromo.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ <h4><br/>Offer valid until May 1st, 2020<br />To submit your business, fill out
<form name="promo" class="needs-validation" novalidate accept-charset="UTF-8"> <!--accept-charset="UTF-8" action="https://formkeep.com/f/exampletoken" method="POST"-->
<div class = "row">
<div class="col-md-5">
<input type="text" required class="form-control promoField" name="name" placeholder="Business Name">
<input type="text" id="name" required class="form-control promoField" name="Business" placeholder="Business Name">
<div class="invalid-feedback">
Please type in the business name
</div>
<input type="url" class="form-control promoField" name="website" required placeholder="Website URL">
<input type="url" class="form-control promoField" id="website" name="Website" required placeholder="Website URL">
<div class="invalid-feedback">
Please type in a valid website URL
</div>
</div>
<div class="col-md-5">
<input type="text" required name="promo_text" class="form-control promoField" id="promo_text" maxlength="100" placeholder="Promotional Text">
<input type="text" required name="Promo" class="form-control promoField" id="promo_text" maxlength="100" placeholder="Promotional Text">
<div class="invalid-feedback">
Please type in a valid text
</div>
Expand All @@ -54,57 +54,99 @@ <h4><br/>Offer valid until May 1st, 2020<br />To submit your business, fill out
<div class="col-md-12 text-center">
<span id="submitText" class="submitText">Thank you! Your ad will be up within 24 hours.</span>
</div>
<div class="col-md-12 text-center">
<span id="errorSubmissionText" class="submitText">We are sorry but there is already a submission created for your business</span>
</div>
<div class="col-md-12 text-center">
<span id="errorText" class="submitText">We are sorry but we are unable to process this Promo form at this time. Please try again later.</span>
</div>
</div>
<span id="key" style="display:hidden">{{ site.env.AIRTABLE_KEY }}</span>
<br>
</div>


<script>
var copyText = document.getElementById("promo_text");
var charLeft = document.getElementById("rem_post");
var submitText = document.getElementById("submitText");
var submitButton = document.getElementById("submitButton");
var forms = document.getElementsByClassName('needs-validation');


function toArray(x) {
for(var i = 0, a = []; i < x.length; i++)
a.push(x[i]);
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not necessary. We load it in the footer.

integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>

return a
}

copyText.addEventListener("input", function(){
var maxlength = this.getAttribute("maxlength");
var currentLength = this.value.length;
<script>
$( document ).ready(function() {
console.log( "ready!" );
});

var copyText = $('#promo_text')[0];
var copyName = $('#name')[0];//document.getElementById("name");
var copySite = $('#website')[0];//document.getElementById("website");
var charLeft = $('#rem_post')[0];//document.getElementById("rem_post");
var errorText = $('#errorText')[0];//document.getElementById("errorText");
var errorSubmissionText = $('#errorSubmissionText')[0];//document.getElementById("errorText");
var submitText = $('#submitText')[0];//document.getElementById("submitText");
var submitButton = $('#submitButton')[0];//document.getElementById("submitButton");
var forms = $("[name='needs-validation']");
//document.getElementsByClassName('needs-validation');

charLeft.innerText = currentLength;
});

(function() {
$(function() {
// We are currently not using babel. ES 5 syntax
'use strict';
window.addEventListener('load', function() {
$( document ).ready(function() {

$('input[type="url"]').on('blur', function(){
var string = $(this).val();
if (!string.match(/^https?:/) && string.length) {
string = "http://" + string;
$(this).val(string)
}
});




// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
if (forms.length > 0) {
for (var form of forms) {
form.addEventListener('submit', function(e) {
console.log("Submitting");
if (!form.checkValidity()) {
e.stopPropagation();

e.preventDefault();
console.log("FORM NOT VALID");
} else {
submitText.style.color = 'black';
submitButton.className = 'btn btn-success';
submitButton.innerHTML = '&check;';
submitButton.disabled = true;
var xhrPost = new XMLHttpRequest();
e.preventDefault();

xhrPost.open('POST', 'https://wduc7ys73l.execute-api.us-east-1.amazonaws.com/dev/promotions', true);
xhrPost.setRequestHeader('Content-Type', 'application/json');

xhrPost.send(JSON.stringify({
"Business":copyName.value,
"Promo":copyText.value,
"Website": copySite.value
}));

xhrPost.onerror = function () {
errorText.className = 'errorText';
e.stopPropagation();
submitButton.className = 'btn btn-danger submitSuccess';
submitButton.innerHTML = 'X';
submitButton.disabled = true;
};

xhrPost.onload = function() {
errorText.className = 'submitText';
submitText.className = 'submitTextSuccess';
submitButton.className = 'btn btn-success submitSuccess';
submitButton.innerHTML = '&check;';
submitButton.disabled = true;
}
}
e.preventDefault();
form.classList.add('was-validated');
});
}
}
}, false);
})();

} , false);
})
</script>
9 changes: 9 additions & 0 deletions _sass/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ div.jumbotron {
margin-bottom:-25px;
}


.promoField{
padding: 15px; margin-top:5px; margin-bottom:5px;
}

.submitTextSuccess{
color:black;
}

.errorText{
color:red;
}