Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

uib-datepicker-popup formatting problem #4616

Closed
char0n opened this issue Oct 14, 2015 · 25 comments
Closed

uib-datepicker-popup formatting problem #4616

char0n opened this issue Oct 14, 2015 · 25 comments

Comments

@char0n
Copy link

char0n commented Oct 14, 2015

Hi,

There seems to be a problem with uib-datepicker-popup and formatting. I am currently using version 0.14.2 but I can confirm that affected was also 0.14.1. The problem is when I declare in html datepicker popup like this:

<input ...uib-datepicker-popup="dd/MM/yyyy"... /> - the date will not be in displayed

When I fallback to

<input ...datepicker-popup="dd/MM/yyyy"... /> - the date will be displayed correctly but I see the deprecation message.

It seems to be a regression in behavior for datepicker-popup. Also note that
uib-datepicker-popup="yyyy-MM-dd" works as expected. But when you change the format to anything different the dates are not displayed anymore.

@char0n
Copy link
Author

char0n commented Oct 14, 2015

Further investigation revealed the cause of the problem. The behavior is not expected only where there is additional attribute on input: required="true" respectively ng-required="true"

@icfantv
Copy link
Contributor

icfantv commented Oct 14, 2015

@char0n, please create a minimal, working plunker that shows the issue and link it here. I want to see if this is a duplicate of #4607.

@char0n
Copy link
Author

char0n commented Oct 14, 2015

Hi,

Here is the plnkr: http://plnkr.co/edit/FMHFNyzC6jlfd43uz6vF?p=preview

I forked the plnkr from @Neilski from #4607 and change version to 0.14.2.

Seems like a 100% duplicate.

@icfantv
Copy link
Contributor

icfantv commented Oct 14, 2015

@char0n, our demo is working fine - please use that as a launching point and feel free to reopen if you think there is still a bug.

@Neilski
Copy link

Neilski commented Oct 14, 2015

Thank you for your continued help.

Using your demo at http://angular-ui.github.io/bootstrap/#/datepicker, if I change line #36 from:

To:

In other words I replace the uib-datepicker-popup value from "{{format}}" to the UK date format of "dd/MM/yyyy" the initial model value is nulled in the first of the two popup date input fields.

This only seems like a problem if:

  • An initial model value is set
  • The attribute ng-required or required is specified
  • the date format is non-default - in my test case UK format (dd/MM/yyyy)

Hope this helps.

@char0n
Copy link
Author

char0n commented Oct 14, 2015

Yes, I can confirm. Thanks.

The only workaround I could come up with is to use old datepicker-popup instead of uib-datepicker-popup.

@icfantv
Copy link
Contributor

icfantv commented Oct 14, 2015

@Neilski, you're missing some text from your comment.

@Neilski
Copy link

Neilski commented Oct 15, 2015

Thank you for your continued help.

Using your demo at http://angular-ui.github.io/bootstrap/#/datepicker

When the page loads, observe that the first date input field (under the 'Popup' heading) contains the value of the date ('15-October-2015')

If you then change line #36 from:

<input type="text"
       class="form-control" 
       uib-datepicker-popup="{{format}}"
       ng-model="dt"
       is-open="status.opened"
       min-date="minDate"
       max-date="maxDate"
       datepicker-options="dateOptions"
       date-disabled="disabled(date, mode)"
       ng-required="true"
       close-text="Close" />

to:

<input type="text"
       class="form-control"
       uib-datepicker-popup="dd/MM/yyyy"
       ng-model="dt"
       is-open="status.opened"
       min-date="minDate"
       max-date="maxDate"
       datepicker-options="dateOptions"
       date-disabled="disabled(date, mode)"
       ng-required="true"
       close-text="Close" />

when the page is refreshed note that the input field is now blank.

In other words if I replace the uib-datepicker-popup value from {{format}} to the UK date format of dd/MM/yyyy the initial model value is nulled in the first of the two popup date input fields.

This only seems like a problem if:

  • An initial model value is set
  • The attribute ng-required or required is specified
  • the date format is non-default - in my test case UK format (dd/MM/yyyy)

Hope this helps.

@icfantv
Copy link
Contributor

icfantv commented Oct 15, 2015

I'm still investigating this, but if you change $scope.format = $scope.formats[0] to $scope.format = $scope.formats[2] in the plunker's example.js it works. Why that is the case I don't know and am still looking into it.

You should be able to use this as a workaround in the interim.

@Neilski
Copy link

Neilski commented Oct 15, 2015

Even more strange is that if I change line #36 of the example.js from

$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];

to

$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd/MM/yyyy', 'shortDate'];

and then change the default formats selection from zero to two (to select the 'dd/MM/yyy' array element on line #37

$scope.format = $scope.formats[2];

It works too. It almost seems to be that the data is being bound before the format statements are being evaluated when the format is presented inline.

@Neilski
Copy link

Neilski commented Oct 15, 2015

I have done a little more testing and I think I can explain the problem. In fact, the problem only exists if you define the date format inline

 uib-datepicker-popup="dd/MM/yyyy"

if you define the format in the scope

$scope.format = "dd/MM/yyyy";

and

 uib-datepicker-popup="{{format}}"

Then everything works as expected. I am guessing that this is due to the ordering of the JavaScript controller and the parsing of the HTML properties. In this respect, the behaviour is understandable if not intuitive.

@icfantv
Copy link
Contributor

icfantv commented Oct 15, 2015

i'm having someone smarter than I look at this. the workaround stinks, but at least one exists.

@aylara
Copy link

aylara commented Feb 16, 2016

If you follow the example of the documentation https://angular-ui.github.io/bootstrap/#/getting_started, you can see using a controller to manage the scope . In my case, if I put a directive does not work. With a controller Yes!

@DiV666
Copy link

DiV666 commented Jul 20, 2016

Hi,

I have another problem with the format, it is that when I use a literal character, the scope loses its value.

For example, "dd 'of' MMMM" or "longDate" which also has literal characters

I made a plunker so you can see how it affects the problem when a calendar date is selected:
http://plnkr.co/edit/txZaESlPRZt0ue2nfKHS?p=preview

Does anyone know how to fix this?

Thank you

@timothylombrana
Copy link

timothylombrana commented Jul 20, 2016

Im having similar error: Version 0.14.3
Ive tried all suggestion above with no success.

<div class="col-sm-2 account-calendar" ng-show="tr.date == 'custom' || tr.date == 'week'">
    <input type="text"
           class="form-control"
           placeholder="Start Date"
           id="startDate"
           ng-click="open($event, 'startDate'); close('endDate');"
           uib-datepicker-mode="'day'"
           max-mode="'day'"
           show-weeks="false"
           uib-datepicker-popup={{userPrefDateFormat}}
           ng-model="tr.startDate"
           is-open="opened.startDate"
           custom-class="setRangeClass(date, mode)"/>

    <div class="icon-calendar" ng-click="open($event, 'startDate'); close('endDate');"></div>
</div>

@icfantv
Copy link
Contributor

icfantv commented Jul 20, 2016

@alphapilgrim 0.14.3 is quite old at this point. you might want to try 1.3.3 or 2.0.0 (but there are some issues w/ nested modals and datepicker model options) in 2.0.

@timothylombrana
Copy link

@icfantv migration to new version is pretty much impossible right now. I need a solution.

@icfantv
Copy link
Contributor

icfantv commented Jul 20, 2016

@alphapilgrim, ok. just so you know, we do not issue patches for back versions.

@timothylombrana
Copy link

@icfantv has this been a known bug?

@MuhammadTayyeb
Copy link

when i edit Datepicker the can't pickup the data.

@icfantv
Copy link
Contributor

icfantv commented Aug 25, 2016

@alphapilgrim, sorry, it's been too long at this point. are you asking if it's a known bug in 0.14.3? if so, i have no idea. if it's a bug in master, we can certainly take a look if a proper issue w/ reproduction is filed.

@MuhammadTayyeb please do not hijack threads. if you require support, please read our project README for how to properly ask for (and receive) help.

@MuhammadTayyeb
Copy link

Kindly see the attachment. when i am edit the date. but they can't show the Edit date. but it will available in backend

capture
taee

@MuhammadTayyeb
Copy link

i use same DatePicker which you. i have issue occur when i am edit the datepciker

@white-hawk-feather
Copy link

I am had a similar problem. I use DatePicker popup in many places and I had this behavior:

  1. No issue when entering the date the first time;
  2. Issue when presenting the form for update. In spite the fact that the date is in ng-model and DatePicker show it when you open the calendar, the bar is blank.

Here 2 samples of the situation I described with the json of the objects and the dates. You see that the first one has the issue, the second no.

screen oggetto 1

screen oggetto 2

Observing the dates I realized that the ones coming from user input have milliseconds, the ones coming from DB do not have milliseconds. I changed the code to have the milliseconds and everything worked fine. The simplest way is doing something like this:

var dateForDatePicker = new Date (dateFromDB);

and everything is working fine, with any formatting string.

@white-hawk-feather
Copy link

I confirm, also if the variable is a DateTime coming from a DB, during initialization you have to do:

yourDate = new Date(yourDate);

and everything works, no format issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants