1
I want to wear the mask xx/xx/xxxx
in a date field and return in the object with the mask, not only the value. I used a directive ui-mask
, but does not return with the mask, already used the model-view-value="true"
but it doesn’t work, so I want to create a directive that just takes the value and adds the "//" bars via javascript
with substring
, only that. But how to use together with ui-mask
? by logic, the directive would have to be executed after the date is all typed?
Follow what I’ve done:
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 doesn’t work, because the execution of it is not calling according, it is called only when loading the page, it would have to be after the field already has the date, to return only to my ng-model the value with the mask. How would it look?
you need to use the directive or would it be a problem to use an external plugin? If you don’t mind, take a look at this: https://github.com/candreoliveira/ngMask is very complete and works well
– celsomtrindade