angular-ui / bootstrap

PLEASE READ THE PROJECT STATUS BELOW. Native AngularJS (Angular) directives for Bootstrap. Smaller footprint (20kB gzipped), no 3rd party JS dependencies (jQuery, bootstrap JS) required. Please read the README.md file before submitting an issue!
http://angular-ui.github.io/bootstrap/
MIT License
14.28k stars 6.73k forks source link

uibDatepickerPopup ngModel formatter position #5089

Open miguel-leon opened 8 years ago

miguel-leon commented 8 years ago

The uibDatepickerPopup ngModel formatter is being pushed instead of unshiftted. The way it is right now, doesn't leave room to work with other directives, as uibDatepickerPopup is priority 0, this formatter is always going to be the first one to execute instead of the last.

Please change at least line 690 of datepicker.js from

ngModel.$formatters.push(function(value) {

to

ngModel.$formatters.unshift(function(value) {

(There's nothing to reproduce using http://plnkr.co/)

wesleycho commented 8 years ago

One could define a directive with negative priority and reorder it.

But I'm wary of changing the order of the formatters - this would most definitely mean we need to rewrite the formatter completely due to the different states of the value, and certainly be a breaking change for users who are modifying the formatters/parsers.

-1 to this request on first glance, I need a lot more information to be convinced.

miguel-leon commented 8 years ago

Hi, There's no priority reordering of existing directives as for example ngModel! It seems only logical to me that formatting to the desired date format should be the last thing to be done. No need to give me -1s as you put it just because you're not convinced.

Here, http://plnkr.co/edit/dtrBkd8lcz7EMUV4LYGF, more information as you requested. The code just harnesses what has been made already with angular ngModel input[date] and with UI Bootstrap to have date inputs with Date object models but at the same time have a locale custom format. I had to manually change the position of the uib-datepicker formatter at line 16 with:

// Reorder uib-datepicker formatter
ngModel.$formatters.unshift(ngModel.$formatters.pop());

It gets only worst when working with multiple directives that also add formatters.

Finally you might think, there's no need to use ngModel, uib-datepicker already does the job of having Date object models. But that is not the point, and one might still want to achieve this with datepickers in some inputs and without them in others, and it should work in all cases, just by adding the final formatter if the datepicker directive is missing.