- Issue created by @Ahmad Khader
- 🇯🇴Jordan Ahmad KhaderI think it is a value issue as you can produce it without any custom code and using only the widget given. 
- Status changed to Needs reviewabout 1 year ago 2:15pm 3 September 2024
When you have a date picker inside the referenced entity that has only years to choose from; all date field values reset to the current date whenever you have any Ajax request.
- set format to yyyy
- set max view to years
- have the field inside any referenced entity.
- try to collapse or add a new reference item.
- observe the issue
Handling year-only values by creating datetime object from that year making it have yyyy-01-01 00:00:00 timestamp
      // Regular expression to check for a year-only input
      $year_regex = '/^\d{4}$/';
      // Check if the input matches the year-only format
      if (preg_match($year_regex, $element['#value'])) {
        // Create a DateTime object with the year only
        $date = DateTime::createFromFormat('Y', $element['#value']);
      } else {
        // Otherwise, try to create the DateTime object with the input directly
        $date = new DateTime($element['#value']);
      }
    
      // Convert it to DrupalDateTime
      $drupal_date = DrupalDateTime::createFromDateTime($date);instead of
$new_date = new DrupalDateTime($element['#value']); Which gives the current date if time are not valid or not enough to make Drupal time stamp
Needs review
2.0
Code
I think it is a value issue as you can produce it without any custom code and using only the widget given.