Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. /*
  2. * Removes unwanted characteres from input while typing
  3. * <input type="text" valueslivefix value="" />
  4. */
  5.  
  6. .directive('valueslivefix', [ function() {
  7.  
  8. return {
  9.  
  10. restrict: "A",
  11. scope: {
  12. t: "@valueslivefix" // read attribute value for switching models of values fixing, i.e. date, month.
  13. },
  14. link: function( scope, element , attrubite ) {
  15.  
  16. var digitsFilter = function( value ) {
  17.  
  18. var regEx = /[A-Z]/ig,
  19. position = ( regEx.test( value ) ) ? 1 : 0;
  20.  
  21. return {
  22. value : value.replace( regEx , ''),
  23. position: position
  24. }
  25.  
  26. },
  27. filtered,
  28. start,
  29. end;
  30.  
  31. element.bind("keyup", function( e ) {
  32.  
  33. start = element[0].selectionStart;
  34. end = element[0].selectionEnd;
  35.  
  36. filtered = digitsFilter( element[0].value );
  37.  
  38. element[0].value = filtered.value;
  39. element[0].setSelectionRange(start, end - filtered.position );
  40.  
  41. return;
  42.  
  43. });
  44.  
  45. // element.bind( "focus" , function( e ) {
  46. //
  47. // changeSomethingOnFocus();
  48. //
  49. // });
  50.  
  51. }
  52.  
  53. }
  54.  
  55. }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement