Created
December 1, 2016 04:46
-
-
Save ryanotella/df6be32d96b90db5cb09b8c00bfa08a0 to your computer and use it in GitHub Desktop.
Generic field duplicate check
This file contains hidden or 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
$('[data-duplicate-check]').on('keyup change', '[data-duplicate-check-url]', _.debounce(function () { | |
var $field = $(this); | |
if($field.val().length < 3) { | |
return; | |
} | |
$.ajax({ | |
url: $field.attr('data-duplicate-check-url'), | |
data: {value: $field.val()} | |
}).done(function (data) { | |
$field.parent().find('.alert-box').remove(); | |
if (!$.isEmptyObject(data)) { | |
$field.after($('<p class="alert-box warning">').text(data.error)); | |
} else { | |
$field.parent().find('.alert-box').remove(); | |
} | |
}); | |
}, 400)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment