Hello guys , i have a big problem with an add email adresse
the goal of this code is to add emailAdresse in a List of EmailAdresse with an input
and below tape suggestion that user can click on it to add in the list, the big problem
is that when i add a emailAdresse in the input : all is ok
when i tape an other emailAdresse and I press on backspace, the app crash “Phory stop working”
the problem happens only after validation of an address written completely in the input when you press backspace on an other adresse email tip in the input ( no suggestions)
this problem is driving me crazy ! ^^"
The html code :
<div class="tag-editor"> <div class="tag-draft addPadding10"> <span class="tag goLeft addPadding5 addMargin5" ng-repeat="email in contactList" ng-click="removeEmail($index)"> {{email}}<span class="remove">x</span> </span> <input class="clear" id="inputEmail" type="text" placeholder="{{'enterEmail' | translate}}" ng-change="addEmail()" ng-trim="false" ng-model="data.inputEmail" > </div> <div class="tag-suggestions colorBgRev" ng-show="contactListSmartphone.length > 0 && data.inputEmail.length > 0"> <span ng-repeat="contact in contactListSmartphone | filter : data.inputEmail : startsWith" ng-click="addEmailSuggestion(contact)"> <span class="tag noBackground addPadding10" ng-if="contactList.indexOf(contact) === -1"> {{contact}} </span> </div> </div>
The Javascript code :
// rajoute d'un email via l'input $scope.addEmail = function () { if ($scope.data.inputEmail.length > 0) { if ($scope.data.inputEmail.charAt($scope.data.inputEmail.length - 1) === " ") { $scope.data.inputEmail = $scope.data.inputEmail.trim(); $scope.data.inputEmail = $scope.data.inputEmail.toLowerCase(); if ($scope.contactList.indexOf($scope.data.inputEmail) === -1) { if (validateEmail($scope.data.inputEmail)) { $scope.contactList.push($scope.data.inputEmail); $scope.data.inputEmail = ""; } } else { $scope.data.inputEmail = ""; } } } };
// rajoute une adresse email via la suggestion $scope.addEmailSuggestion = function (contact) { if ($scope.contactList.indexOf("" + contact) === -1) { $scope.contactList.push(contact); $scope.data.inputEmail = ""; } window.setTimeout(function () { document.getElementById('inputEmail').focus(); }, 0); };
// permet le filtrage sur la valeur de début $scope.startsWith = function (actual, expected) { var lowerStr = (actual + "").toLowerCase(); return lowerStr.indexOf(expected.toLowerCase()) === 0; };
// supprime une adresse email de la liste $scope.removeEmail = function (numItem) { $scope.contactList.splice(numItem, 1); window.setTimeout(function () { document.getElementById('inputEmail').focus(); }, 0); };
y
Thanks for watching and help me in this problem !
SOLVE :
When you have this bug (app crash with backspace) ; you must close the focus and re-add the focus !
$scope.addEmail = function () {
if ($scope.inputShare.email.length > 0) {
if ($scope.inputShare.email.charAt($scope.inputShare.email.length - 1) === " ") {
$scope.inputShare.email = $scope.inputShare.email.trim();
$scope.inputShare.email = $scope.inputShare.email.toLowerCase();
if ($scope.contactList.indexOf($scope.inputShare.email) === -1) {
if (validateEmail($scope.inputShare.email)) {
$scope.contactList.push($scope.inputShare.email);
$scope.inputShare.email = "";
**window.setTimeout(function () {
document.getElementById("inputEmail").blur();
document.getElementById('inputEmail').focus();
}, 0);**
}
} else {
$scope.inputShare.email = "";
}
}
}
};