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.
Comment | File | Size | Author |
---|---|---|---|
#8 | conditional_fields-date_fields_empty-2956612-8.patch | 1.42 KB | jimafisk |
#7 | conditional_fields-date_fields_empty-2956612-7.patch | 1.78 KB | colan |
#7 | interdiff-2956612-2-7.diff | 1.06 KB | colan |
#2 | Date_field_value_is_always_empty-2956612-2.patch | 1.42 KB | yivanov |
Comments
Comment #2
yivanov CreditAttribution: yivanov commentedCreated a patch that removes the last key if the type of the field is Date.
Comment #3
susannecoates CreditAttribution: susannecoates commentedDate_field_value_is_always_empty-2956612-2.patch worked for me. Drupal 8.5.6 with Conditional Fields 8.x-1.0-alpha4
Comment #4
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedComment #5
tim-dielsThe patch works perfect also on the aplha5 release.
Comment #6
yivanov CreditAttribution: yivanov commentedThings 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.
Comment #7
colanA re-roll was needed.
Comment #8
jimafisk CreditAttribution: jimafisk at Jantcu commentedRerolling patch for 8.x-1.0-alpha6
Comment #9
scuba_flyWorks 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.
Comment #10
liquidcms CreditAttribution: liquidcms commentedpatch in #8 works. thanks.
Comment #12
colanThanks all.