Input type Date is always "dirty"

When submitting a form for an entity, the method isDirty() returns always “true” for data of type Date. Whatever the value of the date was changed or not.

if ($this->request->is('post')) {
   $nomhist = $this->Nomhists->patchEntity($nomhist, $this->request->getData());
   if ($nomhist->isDirty('start')) { // -> always true !

Are you sure it’s not updated in the Entity either?

Have you got some custom code in an event listener that’s setting it in a way that marks it dirty? Are the original and current values actually identical in every way?

In NomhistsTable.php, only finder, rules and validators are written.
No computation on dates or what else.
In entity nomhist.php, it’s very light :


namespace App\Model\Entity;

use Cake\ORM\Entity;

 * Nomhist Entity
class Nomhist extends Entity
    protected $_accessible = [
        '*' => true,
        'id' => false

I have several entities with dates : all these entities return dirty=true for unchanged dates !

In bootstrap.php, a set the default format.
But by removing it, it does not change anything.


In AppController.php, I set localization.
But by removing it, it does not change anything.


Yes : I go to the page with the form, submit the form without changing anything, get same values for dates.

Can you give us the output of debug($entity->date_field) both before and after patching?

OK, like this :

if ($this->request->is(['patch', 'post', 'put'])) {
            $nomhist = $this->Nomhists->patchEntity($nomhist, $this->request->getData());

Before :

After :

Not sure if it helps but have you seen the Chapter “Updating Timestamps in Entities” in the Documentation

Thank’s. But this documentation does not help me : the start date is not the timestamp and it is “date” and note “date time” format.