Last active
August 29, 2015 14:27
-
-
Save prokizzle/37f39c896225802494bd to your computer and use it in GitHub Desktop.
Foundation Abide Async Unique Email Validation
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
// 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