From 56adfd7809ff3920a3307aadc211c53c745dd2fd Mon Sep 17 00:00:00 2001 From: Eric Kaden <608341+EricKaden@users.noreply.github.com> Date: Sat, 24 Oct 2026 15:34:00 -0400 Subject: [PATCH] M12: a radio button that must be chosen makes its group required even when an earlier button made the group --- crates/xfa/src/pdf.rs | 12 +++++++++++- crates/xfa/src/tests.rs | 8 +++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/xfa/src/pdf.rs b/crates/xfa/src/pdf.rs index 259d3add51..5a831b07c9 100644 --- a/crates/xfa/src/pdf.rs +++ b/crates/xfa/src/pdf.rs @@ -497,7 +497,17 @@ impl Emitter<'_> { WidgetKind::Radio { group, on, .. } => { top_level = false; let parent = match self.radio_groups.get(group) { - Some((p, _)) => *p, + Some((p, _)) => { + let p = *p; + // A later button that must be chosen makes the group required too. + if w.required { + self.doc.update_dict(p, |g| { + let ff = g.int(b"Ff").unwrap_or(0); + g.set(b"Ff".to_vec(), Object::Int(ff | (1 << 1))); + })?; + } + p + } None => { let mut g = Dict::new(); g.set(b"FT".to_vec(), Object::name("Btn")); diff --git a/crates/xfa/src/tests.rs b/crates/xfa/src/tests.rs index 9175be703e..bfdffdcbc5 100644 --- a/crates/xfa/src/tests.rs +++ b/crates/xfa/src/tests.rs @@ -339,7 +339,8 @@ fn rendering_into_the_pdf_replaces_the_placeholder_page_and_adds_fields() { /// A field or exclusion group that must be filled in (``) becomes a /// Required field, which viewers outline when they highlight a form's fields: a radio group on the -/// group field, its buttons' flags being the group's. `nullTest="warning"` only recommends a value, +/// group field, its buttons' flags being the group's (a button of its own that must be chosen +/// makes the group required too). `nullTest="warning"` only recommends a value, /// so it, like no test, leaves the field optional. #[test] fn fields_that_must_be_filled_in_are_required() { @@ -357,6 +358,10 @@ fn fields_that_must_be_filled_in_are_required() { A + + B + C + "##; let mut doc = Document::open(Arc::new(shell(xdp))).unwrap(); render_into(&mut doc).unwrap(); @@ -378,6 +383,7 @@ fn fields_that_must_be_filled_in_are_required() { assert_eq!(leaf("agree"), Some(true), "a check box too"); assert_eq!(leaf("answer"), Some(true), "the radio group field"); assert_eq!(leaf("optional"), Some(false)); + assert_eq!(leaf("second"), Some(true), "a later button that must be chosen makes its group required"); } /// A dynamic form's own text that the standard fonts can't draw is laid out anyway and reported