- Issue created by @joakland
- ๐บ๐ธUnited States joakland
It turns out it was a
dump()
call in my custom validation function that was causing the issue. I had removed that line above just for simplicity's sake, but it turns out that was the problem! I will need to access the$form_state
object some other way for development purposes.For the record, I don't know why
dump()
causes AJAX to break, but I'll leave that for another time. - ๐บ๐ธUnited States joakland
Well, I spoke too soon. This is still an issue. It would be really great if there were a way to run the custom validation ONLY when the form is submitted. Otherwise, expand/collapse/edit buttons keep throwing errors.
- ๐ณ๐ฟNew Zealand quietone
@joakland, Thanks for the report and helping make Drupal better.
Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.
Also restoring template to keep track of progress and help reviewers and committers.
- First commit to issue fork.
- ๐ฎ๐ณIndia KumudB Ahmedabad
In Drupal 11.x, I have attempted to reproduce the issue by creating a content type and adding fields such as a paragraph field and a date field (which is not required). I applied the validation function to this setup, but I am currently unable to reproduce the error. It seems that the issue might be related to an incorrect validation function name, which could lead to AJAX errors when collapsing or editing paragraph fields in the content type.
To reproduce the issue, follow these steps:
- Create a Content Type: Add the necessary fields, including a paragraph field and a date field.
- Apply the Validation Function: Implement the custom validation function to check the fields as per the requirements.
- Test the Form: Attempt to collapse or edit the paragraph field in the content type and observe if AJAX errors occur. in this code it does not occur.
- If the validation function is incorrect or not properly implemented, it may lead to errors during these actions.
/** * Implements hook_form_alter(). */ function customTweaks_form_alter(&$form, FormStateInterface $form_state, $form_id) { if ($form_id == 'node_product_form' || $form_id == 'node_product_edit_form') { $form['#validate'][] = 'customTweaks_node_form_validate'; } } /** * Custom validation handler for the product node forms. */ function customTweaks_node_form_validate(&$form, FormStateInterface $form_state) { // Only validate if the form is being submitted with published status. if ($form_state->getValue('status')['value'] == 1) { // Check for the product publish date field. if (empty($form_state->getValue('field_prod_publish_date')[0]['value'])) { $form_state->setErrorByName('field_prod_publish_date', t('The publish date field must be completed before publishing.')); } } }