(function () {
    'use strict';

    angular
        .module('editorRotas')
        .directive('emptyInput', emptyInput);

    function emptyInput($parse) {
        var directive = {
            require: 'ngModel',
            link: link
        };

        function link(scope, element, attrs, ngModel) {
            //ngModel should be there & it should be of type text
            if (angular.isObject(ngModel) &&
                (!attrs.type || attrs.type === 'text' || attrs.type === 'number')) {
                
                ngModel.$formatters.push(function (value) {
                    return value || '';
                });
            }
        }

        return directive;
    }
})();
