Skip to content

Instantly share code, notes, and snippets.

@prokizzle
Last active August 29, 2015 14:27
Show Gist options
  • Save prokizzle/37f39c896225802494bd to your computer and use it in GitHub Desktop.
Save prokizzle/37f39c896225802494bd to your computer and use it in GitHub Desktop.
Foundation Abide Async Unique Email Validation
// from http://foundation.zurb.com/forum/posts/1899-zurb-abide-ajax-validation
(function($) {
$.fn.markInvalid = function(text) {
$(this).filter(":input").each(function(i, el) {
var input = $(el);
var container = input.closest(".row");
var label = container.find(".prefix");
var error = container.find("small.error");
label.attr("role", "alert").addClass("error");
input.attr("data-invalid", "");
input.parent().addClass("error");
if(text)
error.text(text);
});
};
})(jQuery)
$(document).on("valid.fndtn.abide", "#reg_username", function(e) {
$.ajax({
data : {
action : "validate.username",
username : $(e.target).val()
},
success : function(data) {
if(!data.success)
$(e.target).markInvalid(data.messages.join('<br>'));
}
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment