statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

Bug: Date fields won't empty or stay empty once you mess with them #1762

Closed beckysoll closed 6 years ago

beckysoll commented 6 years ago

(This is for date fields that are not the date for a dated entry.)

Expected behaviour

For things to work the way they've always worked, if a date field has allow_blank: true it should allow for a blank value to be saved

Actual behaviour

The first time you start a page/entry/whatever, you're shown an "add date" button, as you'd expect. If the date field is left blank. If you leave it blank, edit other fields, and save the page, today's date is saved for that date field. If you've saved and continued, it won't display as such until you refresh the page or leave and come back, if you regular save and open back up, you'll see it. You can delete the date by hitting the x and save... regardless it'll still save the data. if you had a date other than today saved in the field, you've changed your mind and now you want to clear it out, and you do clear it out, it will then continue to save with today's date. You can clear the date from the md file, but once you edit other fields and save, the problem starts all over again.

I first came across this with a date field inside a replicator, but i've tested it right in the root level of the fieldset, makes no difference. I tried making it the only field on the page, same behavior regardless of these tests.

To add complexity, it seems if the date field is inside a replicator set that you had already added to the page's data, before you'd added the date field, and you don't ever open the replicator or interact with the date field, it won't save a date. only after you interact with it, try to clear it out (by default it displays today's date even though none has set) or have it set to an actual date and then try to remove that date), then the problem begins.

Note, i've tried downgrading, and this appears to be an issue with any version 2.8.x, pre 2.8 everything works correctly, as expected.

Steps to reproduce

  1. add a date field to a fieldset. set allow_blank to true.
  2. edit a page or create a new page using that fieldset. don't add a date.
  3. save the page.
  4. go back into the page, or take a look at the page's data, you'll see the date saved anyway.
  5. Try clearing out/deleting the date in the cp, save again. You'll see it saves in the data regardless.
  6. Try removing the data from the pages' md file, go back to the page in the cp, save it again and... you'll see the problem comes back.

Server Details

Operating System: Mac os 10.13.2

Web Server: Apache (via mamp pro)

PHP Version: 7.1.8

Statamic Version: 2.8.0 and upwards

Updated from an older Statamic or fresh install: Updated

List of installed addons: Just my Expires On modifier

Logs

no logs

mikemartin commented 6 years ago

@beckysoll I just ran into this same issue. Both my Start Date and End Date fields save the values:

start_date: 2018-01-30
end_date: 2018-01-30

screenshot 2018-01-30 09 36 01

jasonvarga commented 6 years ago

It's fixed for next release.

jasonvarga commented 6 years ago

Put https://gist.github.com/jasonvarga/284961bbffa816f788a4850288a864eb in statamic/bundles/Date/DateFieldtype.php