Skip to content

Instantly share code, notes, and snippets.

@carolineschnapp
Last active December 11, 2016 12:00
Show Gist options
  • Save carolineschnapp/11167400 to your computer and use it in GitHub Desktop.
Save carolineschnapp/11167400 to your computer and use it in GitHub Desktop.
LIPs validation
{% if template contains 'product' %}
<script>
jQuery(function($) {
$('form[action="/cart/add"]').submit(function() {
var formIsValid = true;
var message = "Please fill this out and you will be able to add the item to your cart.";
$(this).find('[name^="properties"]').filter('.required, [required="required"]').each(function() {
$(this).removeClass('error');
if (formIsValid && $(this).val() == '') {
formIsValid = false;
message = $(this).attr('data-error') || message;
$(this).addClass('error');
}
});
if (formIsValid){
return true;
}
else {
alert(message);
return false;
}
}).find('input, select, textarea').focus(function() {
$(this).removeClass('error');
});
});
</script>
{% endif %}
<style>
input.error, select.error, textarea.error {
border-color: red;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment