I have an input where users search for a pantone color. If the input value matches a pantone name, that pantones information shows up in the dom.
The problem i have is when a user enters a number thats is not in the database, the previous data stays in the dom and isn't cleared. I want to give a message to the user that the color they are searching for isn't in the database and clear the previous data.
this is the code im using to trigger a search
var pantone_data = (data)//data is the json from another file im importing
$('#pantoneSearch').focusout(function(){
var pantoneSearchText = parseInt($('#pantoneSearch').val());
// console.log(pantone_data)
$.each(pantone_data, function(i, obj){
if (pantoneSearchText == obj.name) {
console.log("it sure does")
$('#pantoneTitle').empty();
$('.card-body span').empty();
$('#pantoneTitle').append($('<h3>Pantone ' + obj.name + '</h3>'));
$('#stock1').append($('<p>Stock Name: ' + obj.s1_name + '</p>'));
$('#stock1').append($('<p>Stock Catagory: ' + obj.s1_catagory + '</p>'));
$('#stock1').append($('<p>Pantone Match: ' + obj.s1_pantone_match + '</p>'));
$('#stock1').append($('<p>Delta: ' + obj.s1_delta + '</p>'));
$('#stock2').append($('<p>Stock Name: ' + obj.s2_name + '</p>'));
$('#stock2').append($('<p>Stock Catagory: ' + obj.s2_catagory + '</p>'));
$('#stock2').append($('<p>Pantone Match: ' + obj.s2_pantone_match + '</p>'));
$('#stock2').append($('<p>Delta: ' + obj.s2_delta + '</p>'));
return;
}
else {
console.clear()
console.log("nope")
$('.card-body span').empty();
return;
}
});
});
Right now what happens is that it seems to skip the if statement condition and goes directly to the else statement, clearing everything in the ".card-body span". I need to figure out how to set up the conditoin if the pantoneSearchText does not match any pantone names, clear stuff and add message.
hope this is clear.
Aucun commentaire:
Enregistrer un commentaire