Jump to content

Datefield bug?


onjegolders
 Share

Recommended Posts

Not sure whether this is a known bug or something else is causing the problem.

Basically my custom date field is being wiped when I resave the page.

So on first adding the date and saving all is well, or if the date is added last thing before clicking save then no problems but otherwise the datefield just empties.

I am also using the datepicker (not sure if this has any bearing on it)

Link to comment
Share on other sites

Check out this topic: http://processwire.com/talk/topic/506-problem-with-date-format/

As for the date picker populating the format Y-m-d, it does that because javascript (jQuery) and PHP don't use the same date format strings, so we have to use an ISO-standard date format for something that is automatically populated from a date picker.

You are probably using the d-m-Y format in your date field.

/Jasper

Link to comment
Share on other sites

Thanks Jasper for your help. I've switched it to dashes and it all works now. Unfortunately the datepicker reverts it to YYYY-MM-DD but I understand there's no real way around that and it's not too big a deal!

Link to comment
Share on other sites

There actually is a way around that, but it was a lot more complex than you'd think. :) Had to setup a translation table between PHP date(), PHP strftime(), Javascript/jQuery and regular expressions. But the result is that your date format will be retained without limitation. Grab the file from here, and you should have a lot more options for the datetime fields too:

I'll be committing this to the core soon.

Link to comment
Share on other sites

It's got to be browser cache like Antti said. Hit reload a couple of times in your browser while on a page with the datepicker.

Also, you'll be glad to know I've got an update just about ready that should prevent this particular browser cache issue that comes up regularly. Basically, the admin template will append the module version numbers to the CSS and JS files, i.e. "module.js?v=102", hopefully communicating to the browser that something has changed.

Link to comment
Share on other sites

Thanks for the replies, think I may have just misunderstood, when I select with the datepicker it displays YYYY but when saved it reverts to desired input.

With the new datepicker, the only time you should see the YYYY-MM-DD input is if that what you have selected as your input format. If you have selected some other input format, then the datepicker should use only the format you selected. This is one of the main differences between the new datepicker and the old one. The behavior you are describing sounds to me like you may still have the old datepicker. The new one has been stable for me all week, so I will go ahead and commit the new one to the source this weekend or early next week.

Link to comment
Share on other sites

  • 1 month later...

Hmmm.

In the "live version" on the server, I can't select "unix timestamp" as an output format in datetime fields. On my local dev server (with patch applied) I can. Live version is today's github snapshot. Is this related to that or am I missing something here?

Link to comment
Share on other sites

Seems like he dropped it. I was worried it could be the server since I have to work on a server by a German webhoster which is known to be quirky, but I don't get the unix timestamp option on my local server with the new version, either.

Link to comment
Share on other sites

It was dropped before going into the core just because timestamp is already the native storage state of all date fields. When output formatting is off, date fields are always timestamps. When output formatting is on, you can get the timestamp of any date field like this: $page->getUnformatted ('field_name'); So I figured that having an output formatter that returns an unformatted state probably wasn't worthwhile. :)

Link to comment
Share on other sites

Hey, it got me (who never got his mind around PHP in various attempts), into learning about strftime, strtotime, date and all that stuff this morning. So thanks PW for teaching me yet another lesson in PHP. Watch your backs, I might take the whole thing over some time. ;)

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...