The issue is following:

I have two fields - Date field and Select field.
The Select field has 3 options:
1. A
2. B
3. C

When B is selected, the Date field should become required (and it works without problem). The problem is that even if I fill date in it, it still sets error that the field is required (treats it empty always).

Found where the problem is in conditional_fields.api.inc

Actually, $dependent = $form['#conditional_fields'][reset($element['#array_parents'])]; returns:

$dependent = {array} [2]
 field_parents = {array} [4]
  0 = "field_deadline"
  1 = 0
  2 = "value"
  3 = "date"

And the $form_state->getValues()['field_deadline'] returns:

field_deadline = {array} [1]
 0 = {array} [1]
  value = {Drupal\Core\Datetime\DrupalDateTime} [12]
   dateParts = {array} [6]
   formatTranslationCache = null
   inputTimeRaw = ""
   inputTimeAdjusted = ""
   inputTimeZoneRaw = ""
   inputTimeZoneAdjusted = ""
   inputFormatRaw = ""
   inputFormatAdjusted = ""
   langcode = "en"
   errors = {array} [0]
   dateTimeObject = {DateTime} [3]
   stringTranslation = null

So, the line 312:

$input_state = NestedArray::getValue($form_state->getValues(), $dependent['field_parents'], $key_exists);

is always NULL, since the keys are not the same.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yivanov created an issue. See original summary.

yivanov’s picture

Created a patch that removes the last key if the type of the field is Date.

susannecoates’s picture

Date_field_value_is_always_empty-2956612-2.patch worked for me. Drupal 8.5.6 with Conditional Fields 8.x-1.0-alpha4

SocialNicheGuru’s picture

Status: Active » Needs review
tim-diels’s picture

Version: 8.x-1.0-alpha4 » 8.x-1.0-alpha5
Status: Needs review » Reviewed & tested by the community

The patch works perfect also on the aplha5 release.

yivanov’s picture

Things are moving really slow as far as I see. I fixed this issue 1 year ago and it is not yet committed to the module. I hope that the maintainers of the module will see it.

colan’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.06 KB
1.78 KB

A re-roll was needed.

jimafisk’s picture

Version: 8.x-1.0-alpha5 » 8.x-1.0-alpha6
FileSize
1.42 KB

Rerolling patch for 8.x-1.0-alpha6

scuba_fly’s picture

Status: Needs review » Reviewed & tested by the community

Works for my case.

The issue I had was that I could set the field 'date' to required based on the condition of another field. But it would not validate if I filled in the required date field.

Patch of #8 fixed my problem.

liquidcms’s picture

patch in #8 works. thanks.

  • yivanov authored 520b360 on 8.x-1.x
    Issue #2956612 by colan, yivanov, jimafisk: Date field value is always...
colan’s picture

Status: Reviewed & tested by the community » Fixed

Thanks all.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.