Feat/checkbox radio field filling#246
Open
utkarshqz wants to merge 2 commits intofireform-core:mainfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes silent failure when filling checkbox and radio button fields in output PDFs. Previously, any value the LLM extracted for a checkbox or radio button (e.g.
"yes","female") was written as a plain string directly into the PDF annotation. PDF viewers ignore plain strings on button fields — the checkbox stayed empty and the radio button stayed unselected with no error and no warning.PDF checkboxes and radio buttons require named PDF values like
/Yes,/Off,/Male,/On— the exact name varies per PDF and is defined in the annotation's own appearance stream (AP.N). The old code wrote"yes"(a string) where the PDF expected/Yes(a PdfName). The field appeared empty because the value never matched any valid state.Three helper functions added to
src/filler.py:_get_field_type(annot)— readsFTandFfflags to classify each field astext,checkbox,radio,dropdown, orpushbutton. Previously all fields were treated as text._resolve_checkbox_value(raw, annot)— converts LLM output ("yes","true","x","1","checked") to the correct PdfName. Reads the PDF's ownAP.Nkeys to find the exact on-state name — some PDFs use/Yes, others/Onor a custom label. Falls back to/Yesif AP is missing._fill_annotation(annot, raw_value)— single dispatch function routing each annotation to the correct filling logic. Handles parent radio groups with child kid annotations, plain checkboxes, text fields, and dropdowns. Pushbuttons (Reset/Submit) are explicitly skipped.Also fixed a silent bug in both
fill_form()andfill_form_with_data()—Nonevalues were previously written as the literal string"None"into text fields. Now they write"".docs/SETUP.mdupdated with a supported field types section documenting checkbox and radio button behaviour.Fixes #229
Type of change
How Has This Been Tested?
New test file
tests/test_filler.pycovering all field type detection and value resolution logic."yes","true","x","1","checked"resolve to checked state"no","false","0","","none"resolve to/OffAP.N(e.g./Oninstead of/Yes)/YeswhenAPis missingAP.N/Off/Tx→ text,/BtnFf=0 → checkbox,/BtnFf bit16 → radio, unknown → otherTest Configuration:
Checklist: