I have a webform composed of tree elements:
- a chechbox
- a file upload field (required)
- a text field (required)

The checkbox is used to disable or enable the other two elements.

First I choose a file , enter something in the text field and submit the form. Everything works fine.
Later I want to edit the webform, by checking the checkbox in order to disable the other two fields. While trying to save the webform I get an error message telling me that the File field is required. If I a disable the validation for the file field, the webform can be saved but the previously uploaded file gets lost. In the meantime the value of the text field is preserved.

Is this the intended behaviour of the file element if disabled? Is there any other possibility of disabling a file element while preserving the previously uploaded file?

Comments

sorin_cocorada created an issue. See original summary.

jrockowitz’s picture

The attached webform can be used to debug this issue. The problem is the hidden input containing the file id has "disabled" attribute, which causes the hidden file id to be lost. Personally, I find it strange that a hidden input can be "disabled" and maybe we fix this unexpected behavior.

It is very important to note the default behavior for disabled HTML input is for the value to NOT be sent to the server. What is happening for the text field is the existing value is being preserved. We might need to revisit how webform handles disabled elements via #3043475: [Webform 8.x-6.x] Also clear values when #states_clear = TRUE for disabled #states

jrockowitz’s picture

Status: Active » Needs work

I looked into using the 'read-only' state, but buttons and file uploads don't support a 'read-only' state.

jrockowitz’s picture

jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new751 bytes
sorin_cocorada’s picture

StatusFileSize
new480 bytes

Hello,
Thank you very much for the patch. I applied it and it seems to work.
My first approach was also use the read-only state but I noticed is not supported for file elements.

But another issue arises: if the file element is contained inside a fieldset and the Disable condition is applied at the fieldset level the problem reapers.

jrockowitz’s picture

Status: Needs review » Needs work
StatusFileSize
new4.71 KB

The attached form replicates the issue with the file input nested in a fieldset.

sorin_cocorada’s picture

I made some more tests and the initial problem also occurs for checkboxes.
If the Disable condition is applied to an individual checkbox element the checkbox value gets lost after submitting the form (if Disabled and checkbox stored previously as checked).

fredy davy stalin’s picture

Created a new patch and applied. If the file element is contained inside a fieldset and the Disable condition is applied at the fieldset level the issue resolved.

fredy davy stalin’s picture

Assigned: Unassigned » fredy davy stalin
Issue tags: -file upload disabled state +ContributionWeekend2020
fredy davy stalin’s picture

Status: Needs work » Needs review
fredy davy stalin’s picture

Status: Needs review » Needs work

Found more issues with disabled form elements. Working to resolve the issues.

jrockowitz’s picture

@Fredy Davy Stalin Thanks for working on this issue. We probably need to build a test webform which captures all the issues with the #states disabled state.

fredy davy stalin’s picture

StatusFileSize
new5.5 KB

Attached form can be used to test issues with disabled fields. checkbox and file input field are not saving data when it is in disabled state.

  • 839efdd committed on 3107168-disabled
    Issue #3107168 by jrockowitz, Fredy Davy Stalin, sorin_cocorada:...

  • bd3a1e6 committed on 3107168-disabled
    Issue #3107168 by jrockowitz, Fredy Davy Stalin, sorin_cocorada:...
jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new6.97 KB

The issue is when a fieldset is disabled all inputs within the fieldset are also disabled and their values are not submitted to the server.

The attached patch provides a work-around for this issue by removing the 'disabled' attribute from fieldsets.

  • e744add committed on 3107168-disabled
    Issue #3107168 by jrockowitz, Fredy Davy Stalin, sorin_cocorada:...

  • c96bfd1 committed on 8.x-5.x
    Issue #3107168 by jrockowitz, Fredy Davy Stalin, sorin_cocorada:...
jrockowitz’s picture

I committed the patch. Please download the latest dev release to review.

jrockowitz’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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