Skip to content

Instantly share code, notes, and snippets.

@cargix1
Created September 23, 2015 16:35
Show Gist options
  • Save cargix1/0039565fd832ac5c4dcd to your computer and use it in GitHub Desktop.
Save cargix1/0039565fd832ac5c4dcd to your computer and use it in GitHub Desktop.
Datepicker validation when using ajax cart
1). Add the following code towards the bottom of your theme.liquid file. Ensure it's above the code shown in step 2.
<script>
function checkDateTime() {
$("[name='checkout']").on("click", function() {
var date = $(".zapietCollectionDate").val();
var locationId = $(".clickCollectLocation").val();
if(locationId != 'none') {
if(date == '') {
alert('Please select a pickup date and time.');
return false;
}
}
});
}
</script>
2). In the ajaxifyShopify method at the bottom of your theme.liquid file please add the following line:
onToggleCallback: checkDateTime
You should end up with something that looks like this:
ajaxifyShopify.init({
method: '{{ settings.ajax_cart_method }}',
wrapperClass: 'wrapper',
formSelector: '#addToCartForm',
addToCartSelector: '#addToCart',
cartCountSelector: '.cart-count',
toggleCartButton: '.cart-toggle',
useCartTemplate: true,
btnClass: 'btn',
moneyFormat: {{ shop.money_format | json }},
disableAjaxCart: false,
enableQtySelectors: true,
onToggleCallback: checkDateTime
});
3). Add the following just above the closing <html> tag in your theme.liquid file.
<script type="text/javascript">
$(document).ready(function() {
// On page load run the function.
checkDateTime();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment