Created
November 17, 2015 16:25
-
-
Save weslley39/dc9ef9bc70f0a786b4b9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
angular.module("utils.maxlength", []).directive "rsMaxlength", -> | |
restrict: "A" | |
require: "ngModel" | |
scope: | |
model: "=ngModel" | |
link: (scope, elem, attrs, ctrl) -> | |
attrs.$set "ngTrim", "false" | |
maxlength = parseInt(attrs.rsMaxlength, 10) | |
unless angular.isDefined(attrs.hideInfo) | |
elementInfo = angular.element("<label>Restam <span id=\"qtdRestante\">" + (maxlength - _.size(scope.model)) + "</span> caracteres</label>") | |
elementInfo.insertAfter elem | |
ctrl.$parsers.push (value) -> | |
$("#qtdRestante").html maxlength - value.length | |
if value.length > maxlength | |
value = value.substr(0, maxlength) | |
ctrl.$setViewValue value | |
ctrl.$render() | |
value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment