I implemented a simple search while I feed to my database, so I can see if the record with the name already exists:
function doneTyping() {
$.ajax({
url: $('#existance_route').val(),
type: "GET",
dataType: "json",
data: { place_name: $name_input.val() },
complete: function() {},
success: function(data, textStatus, xhr) {
setupTextfieldsAddonsWith(data);
console.log("Response received!");
},
error: function() {
console.log("AJAX error!");
}
});
};
setupTextfieldsAddonsWith(data)
just simply tell the user (by the UI) that a records exists or not.
However I have an issue. Sometimes when I go to the link to create a new record, it just doesn't work. But then I reload the page manually and it starts working.
Does anyone have any idea why I receive such behavior?
PS. If there are "wiser" plugins for doing the thing that I describe please let me know. I only found Client Side Validations but it is now exactly what I need to do
EDIT
This is how I trigger doneTyping (code from one of the SO questions):
var typingTimer;
var doneTypingInterval = 500;
// place_name is an id bind to a text_field
$('#place_name').on('keyup', function() {
clearTimeout(typingTimer);
typingTimer = setTimeout(doneTyping, doneTypingInterval);
});
$('#restaurant_name').on('keydown', function () {
clearTimeout(typingTimer);
});