WeasyPrint
WeasyPrint copied to clipboard
Include radio buttons when processing forms
Hello!
Resolves #1831
This aims to make radio buttons work in forms.
- 🌎 Currently, inputs are collected and rendered individually.
- ⛔ This means that groups of elements, such as radio buttons which may only have one value checked at once, don't have a way to identify other elements in the group.
- ✅ This PR keeps a concept of "forms" in between "page" and "inputs", and uses those forms to build groups of radio buttons.
This is my first time reading the PDF specification (such fun!) so appreciate any scrutiny of the dictionaries I have it making.
Added a few unit tests as well, but here's a working example:
Created with:
import weasyprint
html = '''
<!DOCTYPE html><html><body>
<form><h2>Form 1</h2>
<p>Radio 1:</p>
<label>Option One <input type="radio" name="radio1" value="1"/></label>
<label>Option Two <input type="radio" name="radio1" value="2"/></label>
<p>Radio 2:</p>
<label>Option One <input type="radio" name="radio2" value="1"/></label>
<label>Option Two <input type="radio" name="radio2" value="2"/></label>
</form>
<form id="two">
<h2>Form 2</h2>
<p>Radio 1:</p>
<label>Option One <input type="radio" name="radio1" value="1"/></label>
<label>Option Two <input type="radio" name="radio1" value="2"/></label>
<p>Radio 2:</p>
<label>Option One <input type="radio" name="radio2" value="1"/></label>
<label>Option Two <input type="radio" name="radio2" value="2"/></label>
</form>
</body></html>
'''
weasyprint.HTML(string=html).write_pdf('output.pdf', pdf_forms=True)
Thanks for taking a look. Happy to change / reformat as needed!