Hello,
After reading this, I tried to implement it in a small module named "webform_conditional_mp" but now I get this error when visiting a page with a webform:
The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to _webform_conditional_mp_webform_submission_form_alter_add_unique_id_to_states() must be of the type array, string given, called in /home/public_html/web/modules/webform_conditional_mp/webform_conditional_mp.module on line 29 in _webform_conditional_mp_webform_submission_form_alter_add_unique_id_to_states() (line 51 of modules/webform_conditional_mp/webform_conditional_mp.module).
The line nr. 29 is:
$sub_triggers = _webform_conditional_mp_webform_submission_form_alter_add_unique_id_to_states($sub_triggers, $unique_prefix);
Thank you
Comments
Comment #2
gge commentedOk, so I changed the line 29 from
$sub_triggers = _webform_conditional_mp_webform_submission_form_alter_add_unique_id_to_states($sub_triggers, $unique_prefix);to$sub_triggers = _webform_conditional_mp_webform_submission_form_alter_add_unique_id_to_states(array ($sub_triggers), $unique_prefix);.The error is gone,
data-states-idis correctly added to the form element, but the conditionals are still messed up...Unique prefixes are not added to :input #states selectors.
For example this is how data-drupal-states looks for the email field:
data-drupal-states='{"visible":{".webform-submission-calatorie-node-10-add-form :input[name=\u0022metoda_contact\u0022]":{"value":"E-mail"}},"required":{".webform-submission-calatorie-node-10-add-form :input[name=\u0022metoda_contact\u0022]":{"value":"E-mail"}}}'The same code appear on all webforms.
The webforms are inside of a paragraph, used multiple times on the same page.
Any help?
Thanks
Comment #3
jrockowitz commentedYes, Webforms inside paragraphs are going to the use the main parent node as the source entity which is definitely going to cause duplicate submissions.
@see Paragraphs with a webform field now automatically detect the main source entity for the paragraph
There is no immediate solution, a workaround would be to have each paragraph's webform open in a modal dialog.
Comment #4
gge commentedHonestly, didn't expect that... Thanks.
Comment #5
jrockowitz commentedSo it is possible that we could create an advanced setting which would use a 'Paragraph' as the source entity instead of the paragraph's main node entity. The code that would need to be updated is in \Drupal\webform\WebformSubmissionForm::setEntity
I am pretty sure this would solve your specific issue without introducing any regressions.
The attached patch is proof-of-concept showing how to disable a paragraph's main entity from being used as the source entity.
Comment #6
gge commentedI'm using Webform 8.x-5.1 but the patch can't be applied because inside src/WebformSubmissionForm.php
$source_entity = WebformSourceEntityManager::getMainSourceEntity($source_entity);does not exist. Thanks.Comment #7
jrockowitz commentedAfter 8.x-5.1 we committed #3021262: Unable to get token value [webform_submission:source-entity:?] from a paragraph field. You might need to apply this patch first.
Comment #8
gge commentedI upgraded to Webform 8.x-5.2-rc2, applied #3 and it almost work.
I created a video https://www.youtube.com/watch?v=Y75V22Mib0U and you can see that some conditionals work as expected while others don't.
The form from clip is here: https://d0jir.ply.st/node/1 (simplytest.me)
Thanks.
Comment #9
acI noticed that if a radio group has its wrapper type set to form item then conditional logic for visible/hidden no long works.
Comment #10
jrockowitz commentedPlease create a new ticket for that specific issue.
Comment #11
jrockowitz commented@see #3040443: Conditional visibility not working for radio element with form item wrapper