Force Field Update with default "now" value - last-edited-field

Hi,

i did not found a solution for an automaticaly updated field.
I want to add a field to the blueprint, which automticaly inserts/updates current date and time. So i can have a field for "last edited"
I managed to have a field that automaticaly inserts this field with current time… but i also want it to be updated on the next edit of the file.

  update:
    label:  last edited
    type:   datetime
    width:  1/2
    time:
      interval: 5
      default:  now
    date:
      default: now

when i want to update my file, kirby reads out of the file the field into panel… but not auto-update with current time.

any idea how to do this?

You can use the override option:

fields:
  time:
    label: Date
    type: date
    default: today
    override: true

https://getkirby.com/docs/cheatsheet/panel-fields/date

1 Like

hi, thx for your answer.

it would be nice… but seems not to work with datetime field

edit:
ok… as i know now which keyword i have to use for further research, i found in the forum info about override function not working in datetime… just sperated in date field and time field. that makes it a bit more complicated.

Yes, that’s right, there is just no override option in the datetime field. If you need it, you could make a copy of the field and implement an override option yourself.

To get the last edited date, you can, however, use $page->modified(), no need to have an extra field for that.

Thx a lot for the hint to $page->modified().
i was testing with this feature now… and it reads the attributes of the folder where pages are stored… that’s not a good indicator for file-edits. because this attribute also changes if something is copied. Working with backups or something like this, grow much complicated, when using $page->modified() as indicator for last edit of the site (blog post in my case)
It would be a good indicator, when everything in contentfolder is ONLY touched by kirby panel… but as i wrote, this makes some scenarios complicated…

Since i’m not a coder but more a code-snippet-juggler =) i’m not realy able to implement the override feature…
so i just created a feature request at github