When conditionally hiding some field from the webform, it seems that the hiding is done purely with JS. This leads to the effect that hidden elements flash as visible momentarily before JS kicks in and hides them.
This leads to a bit bad user experience especially with large forms when a lot of unnecessary fields can be first visible and then hidden.
Generally I would think the hidden elements could have a default CSS style of display: none which would then be then toggled off with JS.
I tested doing this with custom classes / css styles but these are not added to the correct DIV in the DOM so to they don't affect the div revealed when the JS kicks in.
Is there any other solution for the problem?
| Comment | File | Size | Author |
|---|---|---|---|
| #89 | Testing Contact webform Webform Demo Site.png | 145.12 KB | jrockowitz |
| #86 | Test States.yml | 1.2 KB | cleo7186 |
| #85 | 3042289-83.patch | 27.04 KB | jrockowitz |
| #85 | interdiff-3042289-78-83.txt | 5.33 KB | jrockowitz |
| #79 | 3042289-78.patch | 22.77 KB | jrockowitz |
Comments
Comment #2
jrockowitz commentedThe issue with hiding elements using 'display:none' is the element's content won't be indexed by any search engines. At the same time, I feel UX trumps SEO.
Here is my first attempt at adding a
.js-webform-hiddenclass to conditionally hidden elements when they are being rendered on the page.Comment #4
jrockowitz commentedComment #6
jrockowitz commentedComment #8
jrockowitz commentedThe attached patch includes test coverage but still requires some manual review.
Comment #57
jrockowitz commentedComment #58
jrockowitz commentedComment #59
heikkiy commentedA note about SEO. According to several posts (for example https://www.seroundtable.com/google-content-tabs-hidden-change-22950.html), Google has changed their view on hidden content because of mobile first approach. So this change is fine both from the SEO and UX point of view.
Comment #60
jrockowitz commented@HeikkiY Can you please thoroughly test this patch.
Comment #61
heikkiy commented@jrockowitz
Of course. I installed 5.2 rc3 + this patch.
I tested this with one form which had a dropdown reference to taxonomy term and it shows markup fields based on the value. That worked fine. Also tested a checkbox condition which also worked.
I also went through a very large multistep form with a lot of conditions. No problems there either.
The UX was a lot better in both cases.
We also have automated tests in place in the project. I will see if we can run this version on the project and report if we bump into any issues. But so far, so good.
Comment #62
jrockowitz commentedThe main regression I want to prevent is unexpectedly hiding an element which is then no longer conditionally displayed via #states.
Comment #63
heikkiy commented@jrockowitz
Yes, we can definitely monitor that.
We did notice one thing. At the moment we have a conditionally hidden webform-flexbox. I think the JS is now triggering a display: block style for the conditionally shown elements? This will break the flexbox container layout. It should instead trigger display: flex for those elements.
Example markup:
<div class="js-webform-states-hidden webform-flexbox js-webform-flexbox js-form-wrapper form-wrapper" data-drupal-selector="edit-flexbox-31" data-drupal-states="{"invisible":{".webform-submission-test-node-31-add-form :input[name=\u0022test1\u0022]":{"checked":true}}}" id="edit-flexbox-31" style="display: block;">Should be instead:
<div class="js-webform-states-hidden webform-flexbox js-webform-flexbox js-form-wrapper form-wrapper" data-drupal-selector="edit-flexbox-31" data-drupal-states="{"invisible":{".webform-submission-test-node-31-add-form :input[name=\u0022test1\u0022]":{"checked":true}}}" id="edit-flexbox-31" style="display: flex;">Comment #65
jrockowitz commentedComment #66
heikkiy commented@jrockowitz
I noticed that patch #65 has changes regarding flexbox. Not 100% sure if it was supposed to tackle the issue I mentioned above with the webform-flexbox, but the issue mentioned above is still valid after the patch.
I can find the following styles from /webform/css/webform.element.flexbox.css
And this gets overridden with display: block when triggering the visibility.
Comment #67
jrockowitz commentedIs the below YAML an accurate representation of the issue?
Are conditional flexboxes working without this patch?
What browser are you using?
Comment #68
jrockowitz commentedWe might be running into https://stackoverflow.com/questions/38491653/jquery-show-a-flex-box/4121...
Comment #69
heikkiy commented@jrockowitz
I debugged this a bit more. It seems it might actually be a regression with 5.2 version of Webform. We are running 5.1 on our staging server and 5.2 in our development server. Staging server shows the flexbox layout correctly. The issue was introduced when I upgraded to 5.2 and applied this patch. Removing the patch does not help.
The following YAML shows elements where the problem occurs:
The problematic part is the element flexbox_31 in step 2 which looses the flexbox styling which as said happens with 5.2 and not with 5.1.
I tried to test this with your example elements, and actually that works fine with 5.2 also. So the problem is somewhere with the example above.
Also related to another ticket https://www.drupal.org/project/webform/issues/3031383, I noticed the previous page and clientside validation issue is still relevant with the example above. If you can also verify this, I could open a new ticket about that.
Comment #70
heikkiy commentedYes, I think https://stackoverflow.com/questions/38491653/jquery-show-a-flex-box/4121... is exactly the same issue I was thinking about in #63.
Comment #71
jrockowitz commentedI can't replicate any flexbox issue using the example from #69.
Are you using the Bartik theme?
What browser are you using?
Comment #72
heikkiy commented@jrockowitz
Tested with Bartik and Chrome 73.0.3683.86.
I tested with 5.1 and 5.2. Attached are screenshots of the problem. In version 5.1 the fields are positioned side by side with flexbox. In 5.2 they are triggered to display block and full width.
The problem also comes back just with composer installing between 5.1 / 5.2 and nothing else changed in the environment.
Comment #73
jrockowitz commentedI am not able to replicate this issue. If this is a regression, please create a new ticket with simplified webform (not multistep) that can be used to replicate the issue.
Comment #74
heikkiy commented@jrockowich
I think I figured it out. The problem occurs when we are using the condition in reverse.
We have the following.
This seems to break the flexbox.
On the other hand, this does not break it:
Do you still want me to report a separate issue for this?
Comment #75
jrockowitz commentedI still am not able to replicate the problem If the issue is occuring without this issue's patch, please create a new ticket.
Comment #76
heikkiy commentedI tested once more with 5.2 and 5.2 + patch. It seems it is related to this patch because without this patch it does seem to work ok with a simpler form. I will try to create a simplytest.me with this.
Comment #77
heikkiy commented@jrockowitz
Installed simplytest.me with 5.2 rc3 + patch.
Broken flexbox: https://d0k5j.ply.st/form/checked-visible
Working flexbox: https://d0k5j.ply.st/form/unchecked-visible
Comment #79
jrockowitz commentedI was finally able to replicate the issue and updated the test webform.
Comment #80
heikkiy commented@jrockowitz
Patch #78 seems to resolve the issue.
Comment #81
jrockowitz commented@HeikkiY Thanks for reviewing this patch.
I am going to hold off committing this patch with hopes that someone else can do a manual review before I commit it.
Comment #84
jrockowitz commentedI think this issue can also help address #3045662: Field Visible on 2nd Page of Wizard When Should be Hidden which is completely removing hidden element via #access and breaking the expected behavior.
The attached uses this issue's new
.js-webform-states-hiddenclass to hide elements instead of#access: FALSEproperty.Comment #85
jrockowitz commentedComment #86
cleo7186 commentedI am trying to add visibility using multiple conditions and i am getting this error: "Argument 2 passed to Drupal\webform\WebformSubmissionConditionsValidator::validateCondition() must be of the type array, null given, called in /var/www/wvufs/docroot/modules/contrib/webform/src/WebformSubmissionConditionsValidator.php on line 539"
Here is the file I am trying to save- I believe it looks correct.
Comment #87
jrockowitz commentedI can't replicate #86 using the latest dev release with this patch.
What values are you entering? Are you using the test tab?
Comment #88
cleo7186 commentedAh, I have no idea what happened, but it seems to be working now. Excuse my ignorance, what is the "test tab" exactly?
I have tested all of my forms and I do not see any issues with them currently.
And by test I mean I just fiddled with the values to check if the proper fields show up, and that they allow me to submit them without any improper validation errors.
I am not familiar with writing unit tests.
Comment #89
jrockowitz commentedThe 'Test' tab just populates your form with dummy data.
Comment #90
cleo7186 commentedOh, okay, thanks.
So far all of my forms seem to be working now with this patch.
Comment #91
jrockowitz commentedThe next steps for this issue are for me to manually review it (again( and create a change record.
Comment #93
jrockowitz commentedI committed the patch and wrote a change record.
Comment #94
jrockowitz commentedComment #95
jrockowitz commentedComment #97
gargsuchi commentedHi @jrockowitz - I have a form where the Submit button is hidden on initial form load, and shows up only when one of the fields is filled.
And the button is flickering, as the fixStatesWrapper function does not add the class 'js-webform-states-hidden' to the submit button.
Could you guide me where I should be adding it - and I can try to create a patch for the same?
Comment #98
jrockowitz commentedPlease create a new ticket and provide an example webform.