zopefoundation / z3c.form

An advanced form and widget framework for Zope 3
Other
8 stars 39 forks source link

Avoid duplicate IDs when using `QuerySourceRadioWidget` for non-required fields. #62

Closed pgrunewald closed 7 years ago

pgrunewald commented 7 years ago

This problem seems to be related with this commit. I found out in my setup, that it was possible to generate two input elements with duplicate IDs (ending with "-0"), when using a non-required field with QuerySourceRadioWidget. Since QuerySourceRadioWidget uses "-novalue" for the --NOVALUE-- item, I would suggest to use it here as well (also see source). Otherwise <label for=".."/> and the input element's ID would not match.

icemac commented 7 years ago

@pgrunewald Do you think you can make this PR ready for merge by adding a test which breaks without your code change and by looking into my change request?

pgrunewald commented 7 years ago

@icemac: Sorry for the late response. I was busy the last days. Sure, I can provide both the code changes and the required test in my PR. I will provide these within this week.

pgrunewald commented 7 years ago

@icemac: I added the required input as requested. For easier comparision, I appended the test output when running the old code case against the new test:

File "/src/z3c.form/src/z3c/form/browser/radio.txt", line 175, in radio.txt
Failed example:
    print(widget.renderForValue(SequenceWidget.noValueToken))
Expected:
  <html>
    <body>
      <input class="radio-widget" id="widget-id-novalue" name="widget.name" type="radio" value="--NOVALUE--">
    </body>
  </html>

Got:
  <html>
    <body>
      <input class="radio-widget" id="widget-id-0" name="widget.name" type="radio" value="--NOVALUE--">
    </body>
  </html>

Diff:
  <html>
    <body>
      <input class="radio-widget" id="widget-id-novalue (got: widget-id-0)" name="widget.name" type="radio" value="--NOVALUE--">
    </body>
  </html>

Lines with differences:
      <input class="radio-widget" id="widget-id-novalue (got: widget-id-0)" name="widget.name" type="radio" value="--NOVALUE--">
icemac commented 7 years ago

@pgrunewald Thank you for your contribution. I released your change in Version 3.5 on PyPI: https://pypi.org/project/z3c.form/3.5/#id13