I have this code.
$scope.addingDirector = function(id, directorName){
if(directorName){
var find = _.filter($scope.directorArr, function(dir){
//If required use .trim() like directorName.trim().toLowerCase() to strip whitespace
return dir.toLowerCase() == directorName.toLowerCase();
});
if(find.length == 0){
var titleDirector = {
cpPortfolioItemId: id,
name:directorName,
job: 'director'
};
ContentAssessmentFactory.addDirectorName(titleDirector);
$window.alert('Success!')
}else{
$window.alert('Director name already exist.');
}
}else{
$window.alert('You cannot leave a field blank.');
}
};
It checks the input box if there is an existing director name. If not it will add to the database. My problem is, when I click the submit button repeatedly it will add to the database repeatedly too. It will not recheck again the input box for every submit. Can someone help me here?
EDIT: When I close the modal, and then reopen and retype the same name it will prompt that it already exist.
Aucun commentaire:
Enregistrer un commentaire