1

AngularJS

element.bind("keypress", function() {
    if(attrs.id == 'headEdit' && scope.selectedTab.facebook){
        return element.text().length <= 50;
    }
});

Here I can set maximum text length as 50. But when paste some text(cntrl+V) into this box, the text exceeds maximumum length. This problem only in Chrome browser.

Community
  • 1
  • 1
Naveen
  • 757
  • 3
  • 17
  • 41
  • 1
    You could simply return the first 50 character of your element text http://stackoverflow.com/questions/3414916/display-only-10-characters-of-a-long-string – Jack Sep 11 '15 at 08:49

2 Answers2

1

Something Like

element.bind("keypress", function() {
if(attrs.id == 'headEdit' && scope.selectedTab.facebook){
   // return element.text().length <= 50; 
    return    element.val(elem.val().substr(0, 50));
}
});
Jack
  • 526
  • 3
  • 10
  • 30
0

probably it's better to use ng-change?

<input ng-model="someField" ng-change="validate()">

to keep it Angular way

or even better to use ng-paste

<input ng-paste="validate">
Stepan Suvorov
  • 25,118
  • 26
  • 108
  • 176