Created
September 12, 2016 20:17
-
-
Save lscoates/b169adb50b4fedd4613fe8a27137c635 to your computer and use it in GitHub Desktop.
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
// 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