Last active
August 29, 2015 14:15
-
-
Save andresmatasuarez/8ae5ee691f78c4daad22 to your computer and use it in GitHub Desktop.
AngularJS | Directive | Limits an input length by trimming exceeding characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
app = angular.module 'app' | |
app.directive 'limitLength', -> | |
require : 'ngModel' | |
restrict : 'A' | |
link : ($scope, element, attrs, ngModel) -> | |
ngModel.$parsers.push (value) -> | |
if !_.isEmpty(value) and value.length > attrs.limitLength | |
value = ngModel.$modelValue | |
ngModel.$setViewValue value | |
ngModel.$render() | |
value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment