I want to use the xx/xx/xxxx
mask in a date field and return the object with the mask, not just the value. I used a ui-mask
directive, but it does not return with the mask, I already used model-view-value="true"
but it does not work, so I want to create a directive that just takes the value and add the bars "//" via javascript
with substring
, only this. But how do you use it with ui-mask
? by logic, would the directive have to be executed after the date is all typed?
Here's what I did:
angular.module("modulo").directive("uiDate", function ($filter) {
return {
require: "ngModel",
link: function (scope, element, attrs, ctrl) {
var _formatDate = function (date) {
date = date.replace(/[^0-9]+/g, "");
if(date.length > 2) {
date = date.substring(0,2) + "/" + date.substring(2);
}
if(date.length > 5) {
date = date.substring(0,5) + "/" + date.substring(5,9);
}
return date;
};
}
};
});
But it still does not work, because the execution of it is not calling agreement, it is called only when loading the page, it would have to be after the field already have the date, to return only to my ng-model the value with the mask . How would it look?