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

CommentFileSizeAuthor
#5 3035759-4.patch655 bytesjrockowitz

Comments

gge created an issue. See original summary.

gge’s picture

Ok, 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-id is 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

jrockowitz’s picture

Yes, 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.

gge’s picture

Honestly, didn't expect that... Thanks.

jrockowitz’s picture

StatusFileSize
new655 bytes

So 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.

gge’s picture

I'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.

jrockowitz’s picture

After 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.

gge’s picture

I 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.

ac’s picture

I noticed that if a radio group has its wrapper type set to form item then conditional logic for visible/hidden no long works.

jrockowitz’s picture

Please create a new ticket for that specific issue.

jrockowitz’s picture

Status: Fixed » Closed (fixed)

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