Skip to content

Instantly share code, notes, and snippets.

@lscoates
Created September 9, 2016 18:49
Show Gist options
  • Save lscoates/2a080c3e33a2511e6617e391957130f1 to your computer and use it in GitHub Desktop.
Save lscoates/2a080c3e33a2511e6617e391957130f1 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
var phoneLabel = $('label[for="subscription_customer_attributes_phone"]');
phoneLabel.text(phoneLabel.text() + " *");
});
var form = $("form:first");
var phone = $("#subscription_customer_attributes_phone");
var submitBtn = $("#subscription_submit")
submitBtn.click(function(){
if (phone.val() === "") {
phone.addClass("field-error");
return false;
}
});
form.change(function() {
if (phone.val() != "") {
submitBtn.click(function() {
return true;
});
}
});
$("#subscription_customer_attributes_phone").blur(function() {
if ($(this).val() !== "") {
$(this).removeClass("field-error");
} else {
$(this).addClass("field-error");
}
});
.field-error {
border-color: #ff0000;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment