- Issue created by @joakland
- 🇺🇸United States joakland
I now have a solution for this. It won't surprise anyone who has dealt with this or similar issues that the values of a collapsed paragraph field are not available for validation. Long story short, a custom validation function that is looking for a paragraph field that is in a collapsed state will throw an error unless a conditional is applied. And once that error is thrown, no paragraph-related ajax calls will work. In my case, the name of the paragraph field is "Exhibit Chapter." Here is my custom validation function, which now works.
_clean_exhibit_array()
is a custom function that removes array items that are not actual content.function my_module_node_form_validate($form, FormStateInterface $form_state) { // Chapters validation! First let's remove items that don't have an integer as a key $chapters_array = $form_state->getValue('field_exhibit_chapters'); $chapters = _clean_exhibit_array($chapters_array); // Now let's walk through the chapters! foreach ($chapters as $delta => $chapter) { if (array_key_exists('subform', $chapter)) { // This is what prevents the ajax error // Check for chapter title if (empty($chapter['subform']['field_exhibit_sect_title'][0]['value'])) { $form_state->setErrorByName("field_exhibit_chapters][$delta][subform][field_exhibit_sect_title][0][value", t ('The title field in exhibit chapter @delta must be completed before publishing.', ['@delta' => $delta + 1])); } } } }
This function validates many more fields and subfields than are listed here, but this demonstrates the solution to my original problem. A longer term solution would be for validation to (somehow) automatically work on collapsed fields, but that one is a little above my pay grade at the moment.