I have a directive that validates text input with regexp. I want to forbid user from inputing space characters. The directive works great with spaces inside text, but when user enters trailing or leading spaces, validation not triggers. I know that angular auto trims text input, but I can't use ng-trim = "false" directive, because my angularjs version is 1.0.6. Is there a way to fix this?
I've tried suggestion from How to disable trimming of inputs in AngularJS? for angular 1.0.x, and it partially works - validation invokes when user pastes value, which contains trailing spaces, with "ctrl+v" or mouse, but keyboard input it still not triggering validation.
custom ngTrim directive, which partially works:
app.directive('ngTrim', function() {
return {
require: 'ngModel',
priority: 300,
link: function(scope, iElem, iAttrs, ngModel) {
if (iAttrs.ngTrim === 'false') {
ngModel.$parsers.unshift(function() {
return iElem.val();
});
}
}
}
});