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?
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | 3107168-17.patch | 6.97 KB | jrockowitz |
| #14 | webform.webform.issue_3107168 (3).yml | 5.5 KB | fredy davy stalin |
| #9 | Behaviour-of-file-element-if-disabled-3107168-9.patch | 868 bytes | fredy davy stalin |
| #7 | webform.webform.issue_3107168 (1).yml | 4.71 KB | jrockowitz |
| #6 | webform_fieldset.yml | 480 bytes | sorin_cocorada |
Comments
Comment #2
jrockowitz commentedThe 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
Comment #3
jrockowitz commentedI looked into using the 'read-only' state, but buttons and file uploads don't support a 'read-only' state.
Comment #4
jrockowitz commentedComment #5
jrockowitz commentedComment #6
sorin_cocorada commentedHello,
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.
Comment #7
jrockowitz commentedThe attached form replicates the issue with the file input nested in a fieldset.
Comment #8
sorin_cocorada commentedI 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).
Comment #9
fredy davy stalin commentedCreated 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.
Comment #10
fredy davy stalin commentedComment #11
fredy davy stalin commentedComment #12
fredy davy stalin commentedFound more issues with disabled form elements. Working to resolve the issues.
Comment #13
jrockowitz commented@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.
Comment #14
fredy davy stalin commentedAttached 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.
Comment #17
jrockowitz commentedThe 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.
Comment #19
jrockowitz commentedComment #21
jrockowitz commentedI committed the patch. Please download the latest dev release to review.
Comment #22
jrockowitz commented