You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Tim Stavenger (JIRA)" <ji...@apache.org> on 2008/02/20 14:32:40 UTC

[jira] Issue Comment Edited: (WW-2499) CheckboxInterceptor sets disabled checkboxes to false even if checked

    [ https://issues.apache.org/struts/browse/WW-2499?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43317#action_43317 ] 

tjstavenger edited comment on WW-2499 at 2/20/08 5:31 AM:
------------------------------------------------------------

The following change resolved the problem for me. Change the simple theme's checkbox.ftl last line from:

<input type="hidden" name="__checkbox_${parameters.name?html}" value="${parameters.fieldValue?html}" />

To this:

<input type="hidden" id="__checkbox_${parameters.name?html}" name="__checkbox_${parameters.name?html}" value="${parameters.fieldValue?html}"<#rt/>
<#if parameters.disabled?default(false)>
 disabled="disabled"<#rt/>
</#if>
 />

Adding the ID attribute on the hidden field isn't necessary to get the post from the form submission to work as expected, but it does make it easier to get the hidden field in JavaScript via the document.getElementById() method.





      was (Author: tjstavenger):
    The following change resolved the problem for me. Change the simple theme's checkbox.ftl last line from:

<input type="hidden" name="__checkbox_${parameters.name?html}" value="${parameters.fieldValue?html}" />

To this:

<input type="hidden" name="__checkbox_${parameters.name?html}" value="${parameters.fieldValue?html}"<#rt/>
<#if parameters.disabled?default(false)>
 disabled="disabled"<#rt/>
</#if>
 />




  
> CheckboxInterceptor sets disabled checkboxes to false even if checked
> ---------------------------------------------------------------------
>
>                 Key: WW-2499
>                 URL: https://issues.apache.org/struts/browse/WW-2499
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Interceptors
>    Affects Versions: 2.0.9
>            Reporter: Tim Stavenger
>
> Disabled fields by W3 specifications are not "successful" in that they won't get posted on form submission (http://www.w3.org/TR/html4/interact/forms.html#h-17.12.1). 
> The resulting request parameters for a <s:checkbox disabled="true" /> field look as if the checkbox were enabled and not checked (i.e., the '__checkbox_' parameter is present but not the parameter for the checkbox itself). Therefore the CheckboxInterceptor sets a new request parameter for the checkbox to false.
> However, if a checkbox is disabled this isn't at all what one would want -- rather I would think the CheckboxInterceptor should not set a new request parameter if the checkbox in question is disabled. 
> I think a straight forward solution would be to disable the '__checkbox_' hidden field if the checkbox itself is hidden, though I'm not finding anything in the W3 spec that says hidden fields can be disabled (http://www.w3schools.com/tags/tag_input.asp says they cannot, if you take W3Schools as an authoritative source). With the hidden field disabled, it too would not be posted on form submission and the problem would correct itself. However, the catch here is that the disabled attribute on an input field can be changed via script, so knowledge of the disabled fields needs to be at form submission rather than at page rendering. Perhaps the hidden field could still be used with some documentation in the tag reference/javadoc stating that if scripting is used to enable or disable a checkbox that the appropriate hidden field must be enabled or disabled as well?
> Another potential solution is to add another hidden field for checkboxes that denote the checkbox as disabled (at page rendering anyway). For instance a field starting with the name '__checkbox_disabled_'.   Before setting a new request parameter for the checkbox, the CheckboxInterceptor could look for the appropriate '__checkbox_disabled_' field. If scripting were used to enable the disabled field, the script should also need to change the value of the '__checkbox_disabled_' field such that the CheckboxInterceptor knows what to do.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.