简体   繁体   中英

Struts2 s:checkbox - unwanted input type hidden

My code:

<label class="btn btn-default">
    <s:checkbox name="viewTypeDescr" />&#32;
    <s:text name="name.contentType" />
</label>

The docs: http://struts.apache.org/release/2.3.x/docs/checkbox.html say that it will render a input[type=checkbox]

Instead here's what I get:

<label class="btn btn-default">
    <input type="checkbox" name="viewTypeDescr" value="true" id="search_viewTypeDescr">
    <input type="hidden" id="__checkbox_search_viewTypeDescr" name="__checkbox_viewTypeDescr" value="true"> 
    Content Type
</label>

That added input[type="hidden"] is making the resulting page invalid because a label can have max 1 input inside.

Definition of invalid:

  1. Go to validator.w3.org
  2. Paste the provided HTML code in "Validate by direct input"
  3. Decor it with missing <html><head><title>foo</title></head><body> and </body></html> to lessen the false errors
  4. Select HTML5 ad doctype
  5. Click "Validate"
  6. Get this error: "Line xyz, Column abc: The label element may contain at most one input, button, select, textarea, or keygen descendant."
  7. Go to spec just in case: "The caption can be associated with a specific form control, known as the label element's labeled control, either using the for attribute, or by putting the form control inside the label element itself."
  8. Discover that "If the for attribute is not specified, but the label element has a labelable element descendant, then the first such descendant in tree order is the label element's labeled control."
  9. Add that hidden can't be there " http://www.w3.org/html/wg/drafts/html/master/forms.html#category-label "

Anyway, when you submit your document to QA for validation, they use validator.w3.org and that is all that matters.

What's the reason of that hidden? How could I get rid of it or move it elsewhere?

I created a new theme, with parent=simple, and will use that.

Still don't know what's the supposed purpose of that hidden...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM