Skip to content

Instantly share code, notes, and snippets.

@lscoates
Created September 12, 2016 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lscoates/b169adb50b4fedd4613fe8a27137c635 to your computer and use it in GitHub Desktop.
Save lscoates/b169adb50b4fedd4613fe8a27137c635 to your computer and use it in GitHub Desktop.
// Replace the values in `fieldLabel` and `field` with the field you want to add validations too.
// This example shows how you would require Organization.
$(document).ready(function() {
var fieldLabel = $('label[for="subscription_customer_attributes_organization"]');
fieldLabel.text(fieldLabel.text() + " *");
});
var field = $("#subscription_customer_attributes_organization");
var form = $("#signup-form");
var submitBtn = $("#subscription_submit")
submitBtn.click(function() {
if (field.val() === "") {
field.parent().addClass("has-error");
field.parent().append('<span class="error-message">cannot be blank</span>')
return false;
}
});
form.change(function(){
if (field.val() != "") {
submitBtn.click(function() {
return true;
});
}
});
field.blur(function() {
if ($(this).val() !== "") {
$(this).parent().removeClass("has-error");
} else {
$(this).parent().addClass("has-error");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment