Created
September 23, 2015 16:35
-
-
Save cargix1/0039565fd832ac5c4dcd to your computer and use it in GitHub Desktop.
Datepicker validation when using ajax cart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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