From 756a7fbff941b74ebe5034daf7845fc2398f89f2 Mon Sep 17 00:00:00 2001
From: Eric Kaden <608341+EricKaden@users.noreply.github.com>
Date: Sat, 24 Oct 2026 00:02:40 -0400
Subject: [PATCH 01/10] M12: XFA check boxes and radio buttons run their click
scripts when a click changes them
---
crates/automation/tests/it/automation.rs | 27 ++++++++++++
crates/engine/src/tests.rs | 31 ++++++++++++++
crates/engine/src/xfa.rs | 54 +++++++++++++++++++++---
crates/ui-egui/tests/it/xfa.rs | 29 +++++++++++++
crates/xfa/src/fixtures.rs | 36 ++++++++++++++++
parity/acrobat-features.toml | 4 +-
6 files changed, 173 insertions(+), 8 deletions(-)
diff --git a/crates/automation/tests/it/automation.rs b/crates/automation/tests/it/automation.rs
index 9fd5c4269a..bdf6de9952 100644
--- a/crates/automation/tests/it/automation.rs
+++ b/crates/automation/tests/it/automation.rs
@@ -6833,6 +6833,33 @@ fn xfa_scripts_run_for_buttons_and_field_changes_through_tools() {
assert_eq!(r["alerts"], json!(["Hello 4"]));
}
+/// Filling an XFA check box or radio group through form_fill clicks it, as the app does: the
+/// field's change scripts, then the click scripts of what was clicked.
+#[test]
+fn xfa_check_box_and_radio_clicks_run_through_form_fill() {
+ let dir = workdir("xfa-toggle");
+ std::fs::write(dir.join("toggle.pdf"), pdfcraft_xfa::fixtures::shell(&pdfcraft_xfa::fixtures::toggle_template())).unwrap();
+ let mut a = auto(&dir);
+ let doc = ok(&mut a, "doc_open", json!({ "path": "toggle.pdf" }))["doc"].as_u64().unwrap();
+ let log = |a: &mut Automation| {
+ let f = ok(a, "form_fields", json!({ "doc": doc }));
+ f["fields"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .find(|f| f["name"] == "log")
+ .map(|f| f["value"].as_str().unwrap_or_default().to_string())
+ .unwrap_or_default()
+ };
+ ok(&mut a, "form_fill", json!({ "doc": doc, "values": { "agree": true } }));
+ assert_eq!(log(&mut a), "change 1;click 1;");
+ let fields = ok(&mut a, "form_fields", json!({ "doc": doc }));
+ let answer = fields["fields"].as_array().unwrap().iter().find(|f| f["name"] == "answer").cloned().expect("the radio group");
+ let no = answer["options"].as_array().and_then(|o| o.get(1)).and_then(|o| o.as_str().map(str::to_string)).unwrap_or_else(|| panic!("{answer}"));
+ ok(&mut a, "form_fill", json!({ "doc": doc, "values": { "answer": no } }));
+ assert!(log(&mut a).ends_with("no click;"), "{}", log(&mut a));
+}
+
#[test]
fn doc_info_says_when_a_runaway_script_turned_the_forms_scripts_off() {
let dir = workdir("xfa-scripts-off");
diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs
index ed4e6efa1c..070314e332 100644
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@ -5080,6 +5080,37 @@ fn xfa_data_import_on_a_static_form_replaces_every_value_and_pictures_reach_its_
assert!(xml.contains("Bob") && !xml.contains("1"), "{xml}");
}
+/// A click on an XFA check box or radio button runs the field's change scripts, then the click
+/// scripts of what was clicked, which read the new value, show messages and may ask for the focus;
+/// all as one undo step. A text field's click script doesn't run when its value changes.
+#[test]
+fn xfa_check_box_and_radio_button_clicks_run_their_click_scripts() {
+ let bytes = Arc::new(pdfcraft_xfa::fixtures::shell(&pdfcraft_xfa::fixtures::toggle_template()));
+ let mut s = Session::new();
+ let id = s.open("toggle.pdf", None, bytes, None).expect("opens");
+ let log = |s: &Session| s.get(id).unwrap().form.iter().find(|f| f.name == "log").and_then(|f| f.value.first().cloned()).unwrap_or_default();
+ s.apply(id, Edit::SetFieldValue { name: "agree".into(), value: FieldValue::Check(true) }).unwrap();
+ assert_eq!(log(&s), "change 1;click 1;", "change, then click, each seeing the new value");
+ let out = s.take_js_output(id);
+ assert_eq!(out.alerts, ["Agreed"]);
+ assert!(out.requests.iter().any(|r| matches!(r, pdfcraft_js::Request::Focus(n) if n == "note")), "a click may move the focus: {out:?}");
+ s.apply(id, Edit::SetFieldValue { name: "agree".into(), value: FieldValue::Check(false) }).unwrap();
+ assert_eq!(log(&s), "change 1;click 1;change 0;click 0;", "turning it off is a click too");
+ // One undo step takes back the click and what its scripts did.
+ s.undo(id).unwrap();
+ assert_eq!(log(&s), "change 1;click 1;");
+ // A radio button runs its own click script, the one now on.
+ let state = |s: &Session, i: usize| s.get(id).unwrap().form.iter().find(|f| f.name == "answer").and_then(|f| f.widgets.get(i)?.on_state.clone());
+ let (yes, no) = (state(&s, 0).expect("yes"), state(&s, 1).expect("no"));
+ s.apply(id, Edit::SetFieldValue { name: "answer".into(), value: FieldValue::Radio(Some(no)) }).unwrap();
+ assert!(log(&s).ends_with("no click;"), "{}", log(&s));
+ s.apply(id, Edit::SetFieldValue { name: "answer".into(), value: FieldValue::Radio(Some(yes)) }).unwrap();
+ assert!(log(&s).ends_with("no click;yes click;"), "{}", log(&s));
+ // A text field's value isn't set by a click.
+ s.apply(id, Edit::SetFieldValue { name: "note".into(), value: FieldValue::Text("typed".into()) }).unwrap();
+ assert!(!log(&s).contains("note click"), "{}", log(&s));
+}
+
/// Importing data into a dynamic form adds and removes the rows of its repeating subform to
/// match, and the calculations over them run again.
#[test]
diff --git a/crates/engine/src/xfa.rs b/crates/engine/src/xfa.rs
index 6166426bbf..fa0d2f1fd5 100644
--- a/crates/engine/src/xfa.rs
+++ b/crates/engine/src/xfa.rs
@@ -212,15 +212,28 @@ struct FieldInfo {
on_state: String,
/// List boxes that take several values (one per line in the data).
multi: bool,
+ /// Radio groups: each button's on state and SOM path (each button of an XFA radio group is a
+ /// field of its own, with scripts of its own).
+ buttons: Vec<(String, String)>,
}
+/// The generated fields of `doc`, by name, as the runner tracks them.
fn field_infos(doc: &pdfcraft_cos::Document) -> HashMap {
+ let som_of = |obj: pdfcraft_cos::ObjRef| {
+ let object = doc.get(obj);
+ object.as_dict()?.get(pdfcraft_xfa::SOM_KEY).map(|s| doc.resolve(s))?.as_string().map(|s| s.to_text())
+ };
pdfcraft_forms::fields(doc)
.into_iter()
.map(|f| {
let on_state = f.widgets.first().and_then(|w| w.on_state.clone()).unwrap_or_else(|| "1".into());
let multi = f.kind == pdfcraft_forms::FieldKind::List && f.has(pdfcraft_forms::flags::MULTI_SELECT);
- (f.name, FieldInfo { kind: f.kind, value: f.value, on_state, multi })
+ let buttons = if f.kind == pdfcraft_forms::FieldKind::Radio {
+ f.widgets.iter().filter_map(|w| Some((w.on_state.clone()?, som_of(w.obj)?))).collect()
+ } else {
+ Vec::new()
+ };
+ (f.name, FieldInfo { kind: f.kind, value: f.value, on_state, multi, buttons })
})
.collect()
}
@@ -700,6 +713,22 @@ impl<'a, 'b> Runner<'a, 'b> {
Ok(())
}
+ /// The SOM path of what a click on field `name` (at `som`) turned on or off, when it is a
+ /// check box or a radio group: the check box itself, or the group's radio button now on.
+ /// `None` for other fields, and for a group left with no button on.
+ fn clicked(&mut self, name: &str, som: &str) -> Option {
+ use pdfcraft_forms::FieldKind as K;
+ let f = self.fields().get(name)?;
+ match f.kind {
+ K::CheckBox => Some(som.to_string()),
+ K::Radio => {
+ let on = f.value.first()?;
+ f.buttons.iter().find(|(state, _)| state == on).map(|(_, button)| button.clone())
+ }
+ _ => None,
+ }
+ }
+
fn events_of(&mut self, som: &str, activity: &str) -> Vec {
self.live().events.iter().filter(|e| e.som == som && e.activity == activity).cloned().collect()
}
@@ -823,18 +852,31 @@ pub(crate) fn on_open(doc: &mut pdfcraft_cos::Document, tpl: &Template, run: &mu
r.finish()
}
+/// What a click on a check box or radio button runs once it has set the value, in order: the
+/// field's change scripts (a radio group's, as for any value change), then the click scripts of
+/// what was clicked (the check box, or the radio button now on). Their exit scripts follow, as
+/// after any change. The order is to be confirmed on a synthetic form in another viewer.
+const TOGGLE_ORDER: [&str; 2] = ["change", "click"];
+
/// After fields `names` took new values: each one's change, exit and validate scripts, then
-/// the calculations once (or only those, after a reset). A validate script that answers false,
-/// or fails, shows its message; the value stays, as Acrobat marks the field invalid rather
-/// than reverting it.
+/// the calculations once (or only those, after a reset). A check box or radio button runs its
+/// click scripts too ([`TOGGLE_ORDER`]): it changes only when it is clicked, and a click script
+/// reads the new value. A validate script that answers false, or fails, shows its message; the
+/// value stays, as Acrobat marks the field invalid rather than reverting it.
pub(crate) fn on_changes(doc: &mut pdfcraft_cos::Document, tpl: &Template, names: &[String], run: &mut XfaRun) -> Result<(), String> {
let mut r = Runner::new(doc, tpl, run, OPEN_BUDGET_MS);
for name in names {
let som = r.by_som().iter().find(|(_, f)| *f == name).map(|(s, _)| s.clone());
let Some(som) = som else { continue };
let value = r.fields().get(name).map(|f| f.value.join("\n")).unwrap_or_default();
- for ev in r.events_of(&som, "change").into_iter().chain(r.events_of(&som, "exit")) {
- r.run(&ev, &value)?;
+ let clicked = r.clicked(name, &som);
+ let steps: &[&str] = if clicked.is_some() { &TOGGLE_ORDER } else { &["change"] };
+ for activity in steps.iter().copied().chain(["exit"]) {
+ // A click's scripts are those of what was clicked; the others are the field's.
+ let at = if activity == "click" { clicked.as_deref().unwrap_or(&som) } else { som.as_str() };
+ for ev in r.events_of(at, activity) {
+ r.run(&ev, &value)?;
+ }
}
for ev in r.events_of(&som, "validate") {
let Some(o) = r.run(&ev, &value)? else { continue };
diff --git a/crates/ui-egui/tests/it/xfa.rs b/crates/ui-egui/tests/it/xfa.rs
index cf0fc193b1..cbb5e67d88 100644
--- a/crates/ui-egui/tests/it/xfa.rs
+++ b/crates/ui-egui/tests/it/xfa.rs
@@ -130,6 +130,35 @@ fn click_field(h: &mut Harness<'static, PdfCraftApp>, name: &str) {
h.run_steps(4);
}
+/// Clicking an XFA check box or radio button in the app runs its click script after its change
+/// script; the script's message shows.
+#[test]
+fn xfa_check_box_and_radio_clicks_run_their_click_scripts_in_the_app() {
+ let mut h = open(pdfcraft_xfa::fixtures::shell(&pdfcraft_xfa::fixtures::toggle_template()));
+ wait_for_pages(&mut h);
+ let log = |h: &Harness<'static, PdfCraftApp>| {
+ let s = h.state();
+ s.session.get(s.views[0].id).unwrap().form.iter().find(|f| f.name == "log").and_then(|f| f.value.first().cloned()).unwrap_or_default()
+ };
+ click_field(&mut h, "agree");
+ assert_eq!(log(&h), "change 1;click 1;", "console: {:?}", h.state().js_console.log);
+ assert!(h.query_by_label_contains("Agreed").is_some(), "the click script's message shows");
+ // The second radio button of the group.
+ let p = {
+ let s = h.state();
+ let doc = s.session.get(s.views[0].id).unwrap();
+ let f = doc.form.iter().find(|f| f.name == "answer").expect("the radio group");
+ pdfcraft_ui_egui::forms_ui::field_screen_rect(&s.views[0], &doc.info, f, 1).expect("on screen").center()
+ };
+ h.hover_at(p);
+ h.run_steps(1);
+ h.drag_at(p);
+ h.run_steps(1);
+ h.drop_at(p);
+ h.run_steps(4);
+ assert!(log(&h).ends_with("no click;"), "{}", log(&h));
+}
+
#[test]
fn xfa_buttons_run_their_scripts_in_the_app() {
let mut h = open(pdfcraft_xfa::fixtures::shell(&pdfcraft_xfa::fixtures::scripted_template()));
diff --git a/crates/xfa/src/fixtures.rs b/crates/xfa/src/fixtures.rs
index a0307a6944..be48040a3c 100644
--- a/crates/xfa/src/fixtures.rs
+++ b/crates/xfa/src/fixtures.rs
@@ -234,6 +234,42 @@ pub fn scripted_template() -> String {
.to_string()
}
+/// A form whose check box `agree` logs its change and click scripts (with the value each sees)
+/// into `log`, and whose click also shows "Agreed" and asks for the focus in `note` when it turns
+/// the box on; whose radio group `answer` has buttons `yes` and `no` that log their own clicks;
+/// and whose text field `note` has a click script, which a change of its value doesn't run.
+pub fn toggle_template() -> String {
+ let js = "application/x-javascript";
+ let add = |what: &str| format!(r#"log.rawValue = (log.rawValue || "") + {what} + ";";"#);
+ format!(
+ r##"
+
+
+
+
+
+ Agree10
+
+
+
+ Y
+ N
+
+
+
+
+
+
+
+"##,
+ add(r#""change " + this.rawValue"#),
+ add(r#""click " + this.rawValue"#),
+ add(r#""yes click""#),
+ add(r#""no click""#),
+ add(r#""note click""#),
+ )
+}
+
/// [`scripted_template`] with every script in FormCalc (no `contentType`, as Designer writes
/// the default language): the same fields, plus `words`, the total in English words.
pub fn formcalc_template() -> String {
diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml
index 4ec39848c5..abdf561212 100644
--- a/parity/acrobat-features.toml
+++ b/parity/acrobat-features.toml
@@ -5249,8 +5249,8 @@ milestone = "M12"
status = "partial"
commands = ["file.open"]
tools = ["doc_open", "doc_info", "form_fields", "form_fill", "js_run"]
-evidence = ["crates/xfa/src/tests.rs::layout_places_captions_fields_and_sizes_containers_to_their_content", "crates/xfa/src/tests.rs::tables_break_across_pages_and_repeat_their_header_row", "crates/xfa/src/tests.rs::rendering_into_the_pdf_replaces_the_placeholder_page_and_adds_fields", "crates/engine/src/tests.rs::dynamic_xfa_forms_are_laid_out_on_open_filled_and_saved_incrementally", "crates/automation/tests/it/automation.rs::dynamic_xfa_forms_open_render_fill_and_save_through_tools", "crates/ui-egui/tests/it/xfa.rs::a_dynamic_xfa_form_is_laid_out_and_filled", "crates/xfa/src/tests.rs::nested_width_less_subforms_lay_out_in_polynomial_time", "crates/js/src/tests.rs::instance_managers_add_remove_and_count", "crates/xfa/src/tests.rs::the_form_tree_carries_values_presence_instances_and_the_events", "crates/engine/src/tests.rs::xfa_scripts_initialize_calculate_validate_toggle_and_add_rows", "crates/engine/src/tests.rs::xfa_date_arithmetic_reads_the_date_as_its_display_picture_shows_it", "crates/automation/tests/it/automation.rs::xfa_scripts_run_for_buttons_and_field_changes_through_tools", "crates/ui-egui/tests/it/xfa.rs::xfa_buttons_run_their_scripts_in_the_app", "crates/engine/src/tests.rs::hostile_xfa_open_scripts_are_merged_capped_kept_from_printing_and_noted", "crates/engine/src/tests.rs::runaway_xfa_calculations_at_open_end_quickly_with_a_report", "crates/ui-egui/tests/it/xfa.rs::a_form_whose_scripts_were_turned_off_at_open_says_so", "crates/ui-egui/tests/it/xfa.rs::scripts_turned_off_by_a_click_bring_a_closed_notice_bar_back", "crates/automation/tests/it/automation.rs::doc_info_says_when_a_runaway_script_turned_the_forms_scripts_off", "crates/xfa/src/tests.rs::the_live_form_of_nested_repeating_subforms_stops_at_its_node_budget", "crates/xfa/src/tests.rs::data_ops_of_one_event_are_one_datasets_rewrite", "crates/xfa/src/tests.rs::choice_lists_signatures_passwords_and_pictures_become_fields_and_images", "crates/xfa/src/tests.rs::choice_values_come_from_the_data_as_saved_values_and_several_for_lists", "crates/xfa/src/tests.rs::pictures_are_sized_from_their_headers_and_hostile_ones_are_refused_unallocated", "crates/engine/src/tests.rs::xfa_choice_lists_signature_and_picture_fields_open_fill_script_and_save", "crates/xfa/src/tests.rs::repeating_subforms_inside_positioned_content_get_their_instances", "crates/engine/src/tests.rs::xfa_rows_in_areas_are_laid_out_read_calculated_and_written_where_adobe_binds_them", "crates/xfa/src/tests.rs::page_area_without_occur_serves_every_body_page", "apps/pdfcraft-cli/tests/it/xfa.rs::info_reports_the_laid_out_pages_and_fields", "apps/pdfcraft-cli/tests/it/xfa.rs::text_reads_the_layout_including_a_page_absent_from_the_placeholder", "apps/pdfcraft-cli/tests/it/xfa.rs::render_matches_the_engine_layout_on_the_second_page", "apps/pdfcraft-cli/tests/it/xfa.rs::a_laid_out_form_keeps_the_original_copy_permissions", "crates/engine/src/tests.rs::filling_growable_xfa_text_reflows_and_undo_restores_the_layout", "crates/engine/src/tests.rs::xfa_text_growth_refreshes_widget_geometry_but_fixed_height_fields_keep_their_widgets", "crates/automation/tests/it/automation.rs::growable_xfa_text_paginates_after_fill_save_and_print", "crates/engine/src/tests.rs::an_xfa_script_that_fails_partway_keeps_what_it_changed_before_the_error", "crates/engine/src/tests.rs::repeated_xfa_print_buttons_run_their_click_script", "crates/automation/tests/it/automation.rs::repeated_xfa_print_buttons_work_through_tools_and_after_reopen", "crates/xfa/src/tests.rs::rich_text_max_length_reaches_the_field_and_layout", "crates/automation/tests/it/automation.rs::xfa_rich_text_max_length_is_reported_and_enforced_through_tools", "crates/xfa/src/tests.rs::bmp_and_tiff_pictures_are_decoded_and_drawn"]
-notes = "Changed growable multiline text (no fixed h) reflows from final datasets after edits, with or without scripts; pages/widgets refresh and undo/redo, save/reopen and print retain all text. Oversized text still uses the existing read-only page-text fallback with a warning; fixed-height fields do not reflow. Repeated page-master buttons resolve their own PDF field to the shared XFA click script; the numPages-based print script requests printing from every copy, including after save/reopen (#2572). Rich-text exData/maxLength is carried into AcroForm MaxLen, reported by form_fields and enforced by form_fill (Unicode characters); limits and accepted values survive save/reopen (#2570). laid out from the template on open by the xfa crate (positioned, tb, lr-tb, table/row, page masters (a page area with no occur repeats without limit, one with occur max=1 is used once, one with occur min=1 the body never reached gets a page after the body, as Acrobat Pro does on a synthetic form), breaks, repeated header rows, captions, rich text, JPEG/PNG/GIF/BMP/TIFF images) into real pages and AcroForm fields (text, password, date with AFDate formats, check boxes, radio groups, drop-downs and list boxes with shown/saved item pairs and multi-select, signature fields, image fields showing their picture (pictures decoded once per document, at most 20 million pixels, and reused across re-layouts), buttons with reset/print/save/URL), filled from the datasets packet (including rows another viewer added), saved as an incremental revision with the values merged into the datasets so Adobe's viewers show them; doc_info reports xfa_layout. CLI info reports the laid-out page/field counts and dimensions while retaining the input file size and raw counts as pdf_pages/acroform_fields; text and render use those pages too, preserving copy permissions and leaving the source file unchanged (#1645). XFA JavaScript and FormCalc (form.xfa-formcalc) run in the js crate's XFA object model (xfa.form, SOM resolution, rawValue, formattedValue in a date display picture's pattern (number and text display pictures still give the raw value), presence, access, instance managers, xfa.host, xfa.layout, xfa.event): initialize and calculate on open, exit, validate and calculate after a field changes, click for buttons (through js_run and the app), with rows added and removed, subforms shown and hidden, and the form laid out again, all as one undo step and kept in the file. All the scripts of one event run on one thread, each in a fresh context on the form as the engine holds it then (nothing shared between scripts; the live form kept up to date in place for values, rebuilt only when the structure changed), so hundreds of calculations run within the open budget. Hostile scripts are bounded per event (merged and capped effects, messages and console lines, lower loop limits and a time budget on open and calculate, one datasets rewrite per event, print/save/links/focus from clicks only, a runaway script abandoned and the form's scripts turned off, which the app says in a toast and on the notice bar, with a button to the JavaScript console, and doc_info reports as xfa_scripts_off) and what open-time scripts changed is noted. A script that fails partway keeps what it changed before the error, as JavaScript does (forms often trip over an object an earlier version had after their first lines did the work). Missing: a page area's relevant=\"-print\" (on a synthetic form Acrobat still prints the page but leaves it blank; PdfCraft prints its content, #2574); a page break before the first section (Acrobat opens an empty body page first when the first section has breakBefore targetType=pageArea, with or without startNew, as seen on synthetic forms; PdfCraft skips a break on an empty page and lays out one page fewer, #2574); loops inside nested calls are only stopped by abandoning their thread, and script memory is not capped; the change event per keystroke; xfa.template, connections and data descriptions; a hidden instance of a repeating subform hides them all; barcodes are drawn as their text, not bars; keep rules; metrics are approximate and Acrobat fidelity is eyeballed on real forms, not measured (#60)"
+evidence = ["crates/xfa/src/tests.rs::layout_places_captions_fields_and_sizes_containers_to_their_content", "crates/xfa/src/tests.rs::tables_break_across_pages_and_repeat_their_header_row", "crates/xfa/src/tests.rs::rendering_into_the_pdf_replaces_the_placeholder_page_and_adds_fields", "crates/engine/src/tests.rs::dynamic_xfa_forms_are_laid_out_on_open_filled_and_saved_incrementally", "crates/automation/tests/it/automation.rs::dynamic_xfa_forms_open_render_fill_and_save_through_tools", "crates/ui-egui/tests/it/xfa.rs::a_dynamic_xfa_form_is_laid_out_and_filled", "crates/xfa/src/tests.rs::nested_width_less_subforms_lay_out_in_polynomial_time", "crates/js/src/tests.rs::instance_managers_add_remove_and_count", "crates/xfa/src/tests.rs::the_form_tree_carries_values_presence_instances_and_the_events", "crates/engine/src/tests.rs::xfa_scripts_initialize_calculate_validate_toggle_and_add_rows", "crates/engine/src/tests.rs::xfa_date_arithmetic_reads_the_date_as_its_display_picture_shows_it", "crates/automation/tests/it/automation.rs::xfa_scripts_run_for_buttons_and_field_changes_through_tools", "crates/ui-egui/tests/it/xfa.rs::xfa_buttons_run_their_scripts_in_the_app", "crates/engine/src/tests.rs::hostile_xfa_open_scripts_are_merged_capped_kept_from_printing_and_noted", "crates/engine/src/tests.rs::runaway_xfa_calculations_at_open_end_quickly_with_a_report", "crates/ui-egui/tests/it/xfa.rs::a_form_whose_scripts_were_turned_off_at_open_says_so", "crates/ui-egui/tests/it/xfa.rs::scripts_turned_off_by_a_click_bring_a_closed_notice_bar_back", "crates/automation/tests/it/automation.rs::doc_info_says_when_a_runaway_script_turned_the_forms_scripts_off", "crates/xfa/src/tests.rs::the_live_form_of_nested_repeating_subforms_stops_at_its_node_budget", "crates/xfa/src/tests.rs::data_ops_of_one_event_are_one_datasets_rewrite", "crates/xfa/src/tests.rs::choice_lists_signatures_passwords_and_pictures_become_fields_and_images", "crates/xfa/src/tests.rs::choice_values_come_from_the_data_as_saved_values_and_several_for_lists", "crates/xfa/src/tests.rs::pictures_are_sized_from_their_headers_and_hostile_ones_are_refused_unallocated", "crates/engine/src/tests.rs::xfa_choice_lists_signature_and_picture_fields_open_fill_script_and_save", "crates/xfa/src/tests.rs::repeating_subforms_inside_positioned_content_get_their_instances", "crates/engine/src/tests.rs::xfa_rows_in_areas_are_laid_out_read_calculated_and_written_where_adobe_binds_them", "crates/xfa/src/tests.rs::page_area_without_occur_serves_every_body_page", "apps/pdfcraft-cli/tests/it/xfa.rs::info_reports_the_laid_out_pages_and_fields", "apps/pdfcraft-cli/tests/it/xfa.rs::text_reads_the_layout_including_a_page_absent_from_the_placeholder", "apps/pdfcraft-cli/tests/it/xfa.rs::render_matches_the_engine_layout_on_the_second_page", "apps/pdfcraft-cli/tests/it/xfa.rs::a_laid_out_form_keeps_the_original_copy_permissions", "crates/engine/src/tests.rs::filling_growable_xfa_text_reflows_and_undo_restores_the_layout", "crates/engine/src/tests.rs::xfa_text_growth_refreshes_widget_geometry_but_fixed_height_fields_keep_their_widgets", "crates/automation/tests/it/automation.rs::growable_xfa_text_paginates_after_fill_save_and_print", "crates/engine/src/tests.rs::an_xfa_script_that_fails_partway_keeps_what_it_changed_before_the_error", "crates/engine/src/tests.rs::repeated_xfa_print_buttons_run_their_click_script", "crates/automation/tests/it/automation.rs::repeated_xfa_print_buttons_work_through_tools_and_after_reopen", "crates/xfa/src/tests.rs::rich_text_max_length_reaches_the_field_and_layout", "crates/automation/tests/it/automation.rs::xfa_rich_text_max_length_is_reported_and_enforced_through_tools", "crates/xfa/src/tests.rs::bmp_and_tiff_pictures_are_decoded_and_drawn", "crates/engine/src/tests.rs::xfa_check_box_and_radio_button_clicks_run_their_click_scripts", "crates/automation/tests/it/automation.rs::xfa_check_box_and_radio_clicks_run_through_form_fill", "crates/ui-egui/tests/it/xfa.rs::xfa_check_box_and_radio_clicks_run_their_click_scripts_in_the_app"]
+notes = "Changed growable multiline text (no fixed h) reflows from final datasets after edits, with or without scripts; pages/widgets refresh and undo/redo, save/reopen and print retain all text. Oversized text still uses the existing read-only page-text fallback with a warning; fixed-height fields do not reflow. Repeated page-master buttons resolve their own PDF field to the shared XFA click script; the numPages-based print script requests printing from every copy, including after save/reopen (#2572). Rich-text exData/maxLength is carried into AcroForm MaxLen, reported by form_fields and enforced by form_fill (Unicode characters); limits and accepted values survive save/reopen (#2570). laid out from the template on open by the xfa crate (positioned, tb, lr-tb, table/row, page masters (a page area with no occur repeats without limit, one with occur max=1 is used once, one with occur min=1 the body never reached gets a page after the body, as Acrobat Pro does on a synthetic form), breaks, repeated header rows, captions, rich text, JPEG/PNG/GIF/BMP/TIFF images) into real pages and AcroForm fields (text, password, date with AFDate formats, check boxes, radio groups, drop-downs and list boxes with shown/saved item pairs and multi-select, signature fields, image fields showing their picture (pictures decoded once per document, at most 20 million pixels, and reused across re-layouts), buttons with reset/print/save/URL), filled from the datasets packet (including rows another viewer added), saved as an incremental revision with the values merged into the datasets so Adobe's viewers show them; doc_info reports xfa_layout. CLI info reports the laid-out page/field counts and dimensions while retaining the input file size and raw counts as pdf_pages/acroform_fields; text and render use those pages too, preserving copy permissions and leaving the source file unchanged (#1645). XFA JavaScript and FormCalc (form.xfa-formcalc) run in the js crate's XFA object model (xfa.form, SOM resolution, rawValue, formattedValue in a date display picture's pattern (number and text display pictures still give the raw value), presence, access, instance managers, xfa.host, xfa.layout, xfa.event): initialize and calculate on open, exit, validate and calculate after a field changes, click for buttons (through js_run and the app) and for check boxes and radio buttons each time a click changes them, after their change scripts, a radio button running its own (in the app and through form_fill), with rows added and removed, subforms shown and hidden, and the form laid out again, all as one undo step and kept in the file. All the scripts of one event run on one thread, each in a fresh context on the form as the engine holds it then (nothing shared between scripts; the live form kept up to date in place for values, rebuilt only when the structure changed), so hundreds of calculations run within the open budget. Hostile scripts are bounded per event (merged and capped effects, messages and console lines, lower loop limits and a time budget on open and calculate, one datasets rewrite per event, print/save/links/focus from clicks only, a runaway script abandoned and the form's scripts turned off, which the app says in a toast and on the notice bar, with a button to the JavaScript console, and doc_info reports as xfa_scripts_off) and what open-time scripts changed is noted. A script that fails partway keeps what it changed before the error, as JavaScript does (forms often trip over an object an earlier version had after their first lines did the work). Missing: a page area's relevant=\"-print\" (on a synthetic form Acrobat still prints the page but leaves it blank; PdfCraft prints its content, #2574); a page break before the first section (Acrobat opens an empty body page first when the first section has breakBefore targetType=pageArea, with or without startNew, as seen on synthetic forms; PdfCraft skips a break on an empty page and lays out one page fewer, #2574); loops inside nested calls are only stopped by abandoning their thread, and script memory is not capped; the change event per keystroke; xfa.template, connections and data descriptions; a hidden instance of a repeating subform hides them all; barcodes are drawn as their text, not bars; keep rules; metrics are approximate and Acrobat fidelity is eyeballed on real forms, not measured (#60)"
[[feature]]
id = "form.xfa-formcalc"
From e550622877d18f2cee9143a189d5ce7756344d2c Mon Sep 17 00:00:00 2001
From: Eric Kaden <608341+EricKaden@users.noreply.github.com>
Date: Sat, 24 Oct 2026 00:14:52 -0400
Subject: [PATCH 02/10] M12: a check box or radio button set to the value it
had runs no click scripts
---
crates/engine/src/lib.rs | 6 ++++--
crates/engine/src/tests.rs | 9 +++++++++
crates/engine/src/xfa.rs | 22 +++++++++++++++++-----
3 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index 86fc9dce4f..a76efe7688 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -3912,8 +3912,10 @@ impl Session {
if !changed.is_empty() || reset {
let mut run = xfa::XfaRun { page_count: cx.pages, out: &mut cx.xfa_out, datasets: cx.xfa_datasets, ran_away: false };
// Every changed field's scripts, then the calculations once (after a reset,
- // only those).
- let ran = guard(|| xfa::on_changes(&mut next, &tpl, &changed, &mut run))
+ // only those). The values before the edit tell a click from a value set again.
+ let before: std::collections::HashMap> =
+ doc.form.iter().filter(|f| changed.contains(&f.name)).map(|f| (f.name.clone(), f.value.clone())).collect();
+ let ran = guard(|| xfa::on_changes(&mut next, &tpl, &changed, &before, &mut run))
.unwrap_or_else(|m| Err(format!("the form's scripts failed unexpectedly ({m})")));
cx.xfa_datasets = run.datasets;
cx.xfa_ran_away |= run.ran_away;
diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs
index 070314e332..9636c7b816 100644
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@ -5109,6 +5109,15 @@ fn xfa_check_box_and_radio_button_clicks_run_their_click_scripts() {
// A text field's value isn't set by a click.
s.apply(id, Edit::SetFieldValue { name: "note".into(), value: FieldValue::Text("typed".into()) }).unwrap();
assert!(!log(&s).contains("note click"), "{}", log(&s));
+ // A value set again, unchanged, isn't a click: no click script, no message or request.
+ let _ = s.take_js_output(id);
+ let seen = log(&s);
+ s.apply(id, Edit::SetFieldValue { name: "agree".into(), value: FieldValue::Check(true) }).unwrap();
+ s.apply(id, Edit::SetFieldValue { name: "answer".into(), value: FieldValue::Radio(Some(state(&s, 0).unwrap())) }).unwrap();
+ let after = log(&s);
+ assert!(!after.get(seen.len()..).unwrap_or_default().contains("click"), "{after}");
+ let out = s.take_js_output(id);
+ assert!(out.alerts.is_empty() && out.requests.is_empty(), "{out:?}");
}
/// Importing data into a dynamic form adds and removes the rows of its repeating subform to
diff --git a/crates/engine/src/xfa.rs b/crates/engine/src/xfa.rs
index fa0d2f1fd5..7762674f3e 100644
--- a/crates/engine/src/xfa.rs
+++ b/crates/engine/src/xfa.rs
@@ -715,10 +715,14 @@ impl<'a, 'b> Runner<'a, 'b> {
/// The SOM path of what a click on field `name` (at `som`) turned on or off, when it is a
/// check box or a radio group: the check box itself, or the group's radio button now on.
- /// `None` for other fields, and for a group left with no button on.
- fn clicked(&mut self, name: &str, som: &str) -> Option {
+ /// `None` for other fields, for a group left with no button on, and when the value is still
+ /// `before` (set again, not clicked).
+ fn clicked(&mut self, name: &str, som: &str, before: Option<&Vec>) -> Option {
use pdfcraft_forms::FieldKind as K;
let f = self.fields().get(name)?;
+ if before.is_some_and(|b| *b == f.value) {
+ return None;
+ }
match f.kind {
K::CheckBox => Some(som.to_string()),
K::Radio => {
@@ -862,14 +866,22 @@ const TOGGLE_ORDER: [&str; 2] = ["change", "click"];
/// the calculations once (or only those, after a reset). A check box or radio button runs its
/// click scripts too ([`TOGGLE_ORDER`]): it changes only when it is clicked, and a click script
/// reads the new value. A validate script that answers false, or fails, shows its message; the
-/// value stays, as Acrobat marks the field invalid rather than reverting it.
-pub(crate) fn on_changes(doc: &mut pdfcraft_cos::Document, tpl: &Template, names: &[String], run: &mut XfaRun) -> Result<(), String> {
+/// value stays, as Acrobat marks the field invalid rather than reverting it. `before` holds each
+/// field's value before the edit: a check box or radio group set to the value it had runs no
+/// click scripts, since nothing was clicked.
+pub(crate) fn on_changes(
+ doc: &mut pdfcraft_cos::Document,
+ tpl: &Template,
+ names: &[String],
+ before: &HashMap>,
+ run: &mut XfaRun,
+) -> Result<(), String> {
let mut r = Runner::new(doc, tpl, run, OPEN_BUDGET_MS);
for name in names {
let som = r.by_som().iter().find(|(_, f)| *f == name).map(|(s, _)| s.clone());
let Some(som) = som else { continue };
let value = r.fields().get(name).map(|f| f.value.join("\n")).unwrap_or_default();
- let clicked = r.clicked(name, &som);
+ let clicked = r.clicked(name, &som, before.get(name));
let steps: &[&str] = if clicked.is_some() { &TOGGLE_ORDER } else { &["change"] };
for activity in steps.iter().copied().chain(["exit"]) {
// A click's scripts are those of what was clicked; the others are the field's.
From 629ba855c485e0e6d298c573a626bc72d1eead6c Mon Sep 17 00:00:00 2001
From: Eric Kaden <608341+EricKaden@users.noreply.github.com>
Date: Sat, 24 Oct 2026 00:16:33 -0400
Subject: [PATCH 03/10] M12: docstrings for the functions next to the
click-script change
---
crates/automation/tests/it/automation.rs | 3 +++
crates/engine/src/xfa.rs | 1 +
crates/ui-egui/tests/it/xfa.rs | 2 ++
3 files changed, 6 insertions(+)
diff --git a/crates/automation/tests/it/automation.rs b/crates/automation/tests/it/automation.rs
index bdf6de9952..b07255a467 100644
--- a/crates/automation/tests/it/automation.rs
+++ b/crates/automation/tests/it/automation.rs
@@ -6803,6 +6803,8 @@ fn repeated_xfa_print_buttons_work_through_tools_and_after_reopen() {
check(&mut a, doc);
}
+/// XFA scripts run through the tools: initialize and calculate on opening, calculations after
+/// form_fill, and a button's click script through js_run, adding a row that undo takes away.
#[test]
fn xfa_scripts_run_for_buttons_and_field_changes_through_tools() {
let dir = workdir("xfa-scripts");
@@ -6860,6 +6862,7 @@ fn xfa_check_box_and_radio_clicks_run_through_form_fill() {
assert!(log(&mut a).ends_with("no click;"), "{}", log(&mut a));
}
+/// A form whose opening script runs away has its scripts turned off, and doc_info says so.
#[test]
fn doc_info_says_when_a_runaway_script_turned_the_forms_scripts_off() {
let dir = workdir("xfa-scripts-off");
diff --git a/crates/engine/src/xfa.rs b/crates/engine/src/xfa.rs
index 7762674f3e..dbe4f02371 100644
--- a/crates/engine/src/xfa.rs
+++ b/crates/engine/src/xfa.rs
@@ -733,6 +733,7 @@ impl<'a, 'b> Runner<'a, 'b> {
}
}
+ /// The `activity` scripts of the object at `som` in the live form.
fn events_of(&mut self, som: &str, activity: &str) -> Vec {
self.live().events.iter().filter(|e| e.som == som && e.activity == activity).cloned().collect()
}
diff --git a/crates/ui-egui/tests/it/xfa.rs b/crates/ui-egui/tests/it/xfa.rs
index cbb5e67d88..e114ea8296 100644
--- a/crates/ui-egui/tests/it/xfa.rs
+++ b/crates/ui-egui/tests/it/xfa.rs
@@ -159,6 +159,8 @@ fn xfa_check_box_and_radio_clicks_run_their_click_scripts_in_the_app() {
assert!(log(&h).ends_with("no click;"), "{}", log(&h));
}
+/// Clicking an XFA button in the app runs its click script: one adds a row, another shows its
+/// message as a notice.
#[test]
fn xfa_buttons_run_their_scripts_in_the_app() {
let mut h = open(pdfcraft_xfa::fixtures::shell(&pdfcraft_xfa::fixtures::scripted_template()));
From 8e52d9ec76db0fe95f16c38f806bf2af3ebd0bd5 Mon Sep 17 00:00:00 2001
From: Eric Kaden <608341+EricKaden@users.noreply.github.com>
Date: Sat, 24 Oct 2026 00:20:44 -0400
Subject: [PATCH 04/10] M12: comments for the closures the click-script change
adds
---
crates/automation/tests/it/automation.rs | 1 +
crates/engine/src/tests.rs | 1 +
crates/engine/src/xfa.rs | 1 +
crates/ui-egui/tests/it/xfa.rs | 1 +
crates/xfa/src/fixtures.rs | 1 +
5 files changed, 5 insertions(+)
diff --git a/crates/automation/tests/it/automation.rs b/crates/automation/tests/it/automation.rs
index b07255a467..3a192d38fc 100644
--- a/crates/automation/tests/it/automation.rs
+++ b/crates/automation/tests/it/automation.rs
@@ -6843,6 +6843,7 @@ fn xfa_check_box_and_radio_clicks_run_through_form_fill() {
std::fs::write(dir.join("toggle.pdf"), pdfcraft_xfa::fixtures::shell(&pdfcraft_xfa::fixtures::toggle_template())).unwrap();
let mut a = auto(&dir);
let doc = ok(&mut a, "doc_open", json!({ "path": "toggle.pdf" }))["doc"].as_u64().unwrap();
+ // What the scripts have written to the form's log field so far.
let log = |a: &mut Automation| {
let f = ok(a, "form_fields", json!({ "doc": doc }));
f["fields"]
diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs
index 9636c7b816..dfcae9fd62 100644
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@ -5088,6 +5088,7 @@ fn xfa_check_box_and_radio_button_clicks_run_their_click_scripts() {
let bytes = Arc::new(pdfcraft_xfa::fixtures::shell(&pdfcraft_xfa::fixtures::toggle_template()));
let mut s = Session::new();
let id = s.open("toggle.pdf", None, bytes, None).expect("opens");
+ // What the scripts have written to the form's log field so far.
let log = |s: &Session| s.get(id).unwrap().form.iter().find(|f| f.name == "log").and_then(|f| f.value.first().cloned()).unwrap_or_default();
s.apply(id, Edit::SetFieldValue { name: "agree".into(), value: FieldValue::Check(true) }).unwrap();
assert_eq!(log(&s), "change 1;click 1;", "change, then click, each seeing the new value");
diff --git a/crates/engine/src/xfa.rs b/crates/engine/src/xfa.rs
index dbe4f02371..857a8a02ad 100644
--- a/crates/engine/src/xfa.rs
+++ b/crates/engine/src/xfa.rs
@@ -219,6 +219,7 @@ struct FieldInfo {
/// The generated fields of `doc`, by name, as the runner tracks them.
fn field_infos(doc: &pdfcraft_cos::Document) -> HashMap {
+ // The SOM path a widget or field records for its XFA object.
let som_of = |obj: pdfcraft_cos::ObjRef| {
let object = doc.get(obj);
object.as_dict()?.get(pdfcraft_xfa::SOM_KEY).map(|s| doc.resolve(s))?.as_string().map(|s| s.to_text())
diff --git a/crates/ui-egui/tests/it/xfa.rs b/crates/ui-egui/tests/it/xfa.rs
index e114ea8296..3fff06651c 100644
--- a/crates/ui-egui/tests/it/xfa.rs
+++ b/crates/ui-egui/tests/it/xfa.rs
@@ -136,6 +136,7 @@ fn click_field(h: &mut Harness<'static, PdfCraftApp>, name: &str) {
fn xfa_check_box_and_radio_clicks_run_their_click_scripts_in_the_app() {
let mut h = open(pdfcraft_xfa::fixtures::shell(&pdfcraft_xfa::fixtures::toggle_template()));
wait_for_pages(&mut h);
+ // What the scripts have written to the form's log field so far.
let log = |h: &Harness<'static, PdfCraftApp>| {
let s = h.state();
s.session.get(s.views[0].id).unwrap().form.iter().find(|f| f.name == "log").and_then(|f| f.value.first().cloned()).unwrap_or_default()
diff --git a/crates/xfa/src/fixtures.rs b/crates/xfa/src/fixtures.rs
index be48040a3c..4530485cfa 100644
--- a/crates/xfa/src/fixtures.rs
+++ b/crates/xfa/src/fixtures.rs
@@ -240,6 +240,7 @@ pub fn scripted_template() -> String {
/// and whose text field `note` has a click script, which a change of its value doesn't run.
pub fn toggle_template() -> String {
let js = "application/x-javascript";
+ // A script line that adds `what` (JavaScript), then ";", to the log field.
let add = |what: &str| format!(r#"log.rawValue = (log.rawValue || "") + {what} + ";";"#);
format!(
r##"
From 0c88cc9c0350c3d8ae1a875aea2f41644cc8de6f Mon Sep 17 00:00:00 2001
From: Eric Kaden <608341+EricKaden@users.noreply.github.com>
Date: Sat, 24 Oct 2026 08:49:37 -0400
Subject: [PATCH 05/10] M12: the click-script UI test waits for the form as
main's tests now do
---
crates/ui-egui/tests/it/xfa.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/crates/ui-egui/tests/it/xfa.rs b/crates/ui-egui/tests/it/xfa.rs
index f9a20984a3..9fb1422139 100644
--- a/crates/ui-egui/tests/it/xfa.rs
+++ b/crates/ui-egui/tests/it/xfa.rs
@@ -132,7 +132,7 @@ fn click_field(h: &mut Harness<'static, PdfCraftApp>, name: &str) {
#[test]
fn xfa_check_box_and_radio_clicks_run_their_click_scripts_in_the_app() {
let mut h = open(pdfcraft_xfa::fixtures::shell(&pdfcraft_xfa::fixtures::toggle_template()));
- wait_for_pages(&mut h);
+ crate::support::settle(&mut h);
// What the scripts have written to the form's log field so far.
let log = |h: &Harness<'static, PdfCraftApp>| {
let s = h.state();
From 8e9b734ed067866daf32b6abaaf3341dae9b1ec8 Mon Sep 17 00:00:00 2001
From: Eric Kaden <608341+EricKaden@users.noreply.github.com>
Date: Sat, 24 Oct 2026 11:34:36 -0400
Subject: [PATCH 06/10] M6: a check box a batch sets twice is clicked once
---
crates/engine/src/tests.rs | 6 ++++++
crates/engine/src/xfa.rs | 10 ++++++++--
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs
index f7a443c061..a91debba49 100644
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@ -5648,6 +5648,12 @@ fn xfa_check_box_and_radio_button_clicks_run_their_click_scripts() {
assert!(!after.get(seen.len()..).unwrap_or_default().contains("click"), "{after}");
let out = s.take_js_output(id);
assert!(out.alerts.is_empty() && out.requests.is_empty(), "{out:?}");
+ // A batch that turns the check box off twice clicks it once: the second set changes nothing.
+ let off = || Edit::SetFieldValue { name: "agree".into(), value: FieldValue::Check(false) };
+ let seen = log(&s);
+ s.apply(id, Edit::Batch { label: "twice".into(), edits: vec![off(), off()] }).unwrap();
+ let after = log(&s);
+ assert_eq!(after.get(seen.len()..).unwrap_or_default().matches("click 0;").count(), 1, "{after}");
}
/// Importing data into a dynamic form adds and removes the rows of its repeating subform to
diff --git a/crates/engine/src/xfa.rs b/crates/engine/src/xfa.rs
index 2e4edc8fef..b1bb5d9c83 100644
--- a/crates/engine/src/xfa.rs
+++ b/crates/engine/src/xfa.rs
@@ -872,7 +872,8 @@ const TOGGLE_ORDER: [&str; 2] = ["change", "click"];
/// reads the new value. A validate script that answers false, or fails, shows its message; the
/// value stays, as Acrobat marks the field invalid rather than reverting it. `before` holds each
/// field's value before the edit: a check box or radio group set to the value it had runs no
-/// click scripts, since nothing was clicked.
+/// click scripts, since nothing was clicked. A field named twice (a batch that sets it twice)
+/// is compared the second time with what the first left, so it is clicked once at most.
pub(crate) fn on_changes(
doc: &mut pdfcraft_cos::Document,
tpl: &Template,
@@ -881,11 +882,13 @@ pub(crate) fn on_changes(
run: &mut XfaRun,
) -> Result<(), String> {
let mut r = Runner::new(doc, tpl, run, OPEN_BUDGET_MS);
+ // Each field's value once its scripts have run, for a later mention of the same field.
+ let mut done: HashMap> = HashMap::new();
for name in names {
let som = r.by_som().iter().find(|(_, f)| *f == name).map(|(s, _)| s.clone());
let Some(som) = som else { continue };
let value = r.fields().get(name).map(|f| f.value.join("\n")).unwrap_or_default();
- let clicked = r.clicked(name, &som, before.get(name));
+ let clicked = r.clicked(name, &som, done.get(name).or_else(|| before.get(name)));
let steps: &[&str] = if clicked.is_some() { &TOGGLE_ORDER } else { &["change"] };
for activity in steps.iter().copied().chain(["exit"]) {
// A click's scripts are those of what was clicked; the others are the field's.
@@ -900,6 +903,9 @@ pub(crate) fn on_changes(
r.alert(ev.message.clone().unwrap_or_else(|| format!("{name}: the value is not valid")));
}
}
+ if let Some(f) = r.fields().get(name) {
+ done.insert(name.clone(), f.value.clone());
+ }
}
r.calculates()?;
r.finish().map(|_| ())
From 3f6471e6648f6811298758804d2e5e02da3346cb Mon Sep 17 00:00:00 2001
From: Eric Kaden <608341+EricKaden@users.noreply.github.com>
Date: Sat, 24 Oct 2026 11:51:59 -0400
Subject: [PATCH 07/10] M6: a radio group's change and click scripts run before
its button's, as another viewer runs them
---
crates/automation/tests/it/automation.rs | 4 ++--
crates/engine/src/tests.rs | 14 ++++++++------
crates/engine/src/xfa.rs | 19 ++++++++++++-------
crates/ui-egui/tests/it/xfa.rs | 2 +-
crates/xfa/src/fixtures.rs | 14 ++++++++++++--
parity/acrobat-features.toml | 2 +-
6 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/crates/automation/tests/it/automation.rs b/crates/automation/tests/it/automation.rs
index 3b9806d665..39f7fa801d 100644
--- a/crates/automation/tests/it/automation.rs
+++ b/crates/automation/tests/it/automation.rs
@@ -7253,7 +7253,7 @@ fn xfa_scripts_run_for_buttons_and_field_changes_through_tools() {
}
/// Filling an XFA check box or radio group through form_fill clicks it, as the app does: the
-/// field's change scripts, then the click scripts of what was clicked.
+/// change scripts, then the click scripts, a radio group's before those of the button now on.
#[test]
fn xfa_check_box_and_radio_clicks_run_through_form_fill() {
let dir = workdir("xfa-toggle");
@@ -7277,7 +7277,7 @@ fn xfa_check_box_and_radio_clicks_run_through_form_fill() {
let answer = fields["fields"].as_array().unwrap().iter().find(|f| f["name"] == "answer").cloned().expect("the radio group");
let no = answer["options"].as_array().and_then(|o| o.get(1)).and_then(|o| o.as_str().map(str::to_string)).unwrap_or_else(|| panic!("{answer}"));
ok(&mut a, "form_fill", json!({ "doc": doc, "values": { "answer": no } }));
- assert!(log(&mut a).ends_with("no click;"), "{}", log(&mut a));
+ assert!(log(&mut a).ends_with("group click;no click;no exit;group exit;"), "{}", log(&mut a));
}
/// A form whose opening script runs away has its scripts turned off, and doc_info says so.
diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs
index a91debba49..03eedb55a8 100644
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@ -5609,9 +5609,10 @@ fn xfa_data_import_on_a_static_form_replaces_every_value_and_pictures_reach_its_
assert!(xml.contains("Bob") && !xml.contains("1"), "{xml}");
}
-/// A click on an XFA check box or radio button runs the field's change scripts, then the click
-/// scripts of what was clicked, which read the new value, show messages and may ask for the focus;
-/// all as one undo step. A text field's click script doesn't run when its value changes.
+/// A click on an XFA check box or radio button runs its change scripts, then its click scripts,
+/// which read the new value, show messages and may ask for the focus; a radio group's run before
+/// those of the button now on. All as one undo step. A text field's click script doesn't run when
+/// its value changes.
#[test]
fn xfa_check_box_and_radio_button_clicks_run_their_click_scripts() {
let bytes = Arc::new(pdfcraft_xfa::fixtures::shell(&pdfcraft_xfa::fixtures::toggle_template()));
@@ -5629,13 +5630,14 @@ fn xfa_check_box_and_radio_button_clicks_run_their_click_scripts() {
// One undo step takes back the click and what its scripts did.
s.undo(id).unwrap();
assert_eq!(log(&s), "change 1;click 1;");
- // A radio button runs its own click script, the one now on.
+ // A radio group runs each activity's scripts, then the button now on runs its own; the
+ // button turned off runs none. Exit scripts follow, the button's first.
let state = |s: &Session, i: usize| s.get(id).unwrap().form.iter().find(|f| f.name == "answer").and_then(|f| f.widgets.get(i)?.on_state.clone());
let (yes, no) = (state(&s, 0).expect("yes"), state(&s, 1).expect("no"));
s.apply(id, Edit::SetFieldValue { name: "answer".into(), value: FieldValue::Radio(Some(no)) }).unwrap();
- assert!(log(&s).ends_with("no click;"), "{}", log(&s));
+ assert!(log(&s).ends_with("group change N;no change;group click;no click;no exit;group exit;"), "{}", log(&s));
s.apply(id, Edit::SetFieldValue { name: "answer".into(), value: FieldValue::Radio(Some(yes)) }).unwrap();
- assert!(log(&s).ends_with("no click;yes click;"), "{}", log(&s));
+ assert!(log(&s).ends_with("no exit;group exit;group change Y;yes change;group click;yes click;yes exit;group exit;"), "{}", log(&s));
// A text field's value isn't set by a click.
s.apply(id, Edit::SetFieldValue { name: "note".into(), value: FieldValue::Text("typed".into()) }).unwrap();
assert!(!log(&s).contains("note click"), "{}", log(&s));
diff --git a/crates/engine/src/xfa.rs b/crates/engine/src/xfa.rs
index b1bb5d9c83..6fcd9db35a 100644
--- a/crates/engine/src/xfa.rs
+++ b/crates/engine/src/xfa.rs
@@ -861,9 +861,10 @@ pub(crate) fn on_open(doc: &mut pdfcraft_cos::Document, tpl: &Template, run: &mu
}
/// What a click on a check box or radio button runs once it has set the value, in order: the
-/// field's change scripts (a radio group's, as for any value change), then the click scripts of
-/// what was clicked (the check box, or the radio button now on). Their exit scripts follow, as
-/// after any change. The order is to be confirmed on a synthetic form in another viewer.
+/// change scripts, then the click scripts, each reading the new value. A radio group runs each
+/// activity's scripts, then the radio button now on runs its own; the button it turned off runs
+/// none. Exit scripts follow, as after any change: the button's, then the group's. This is the
+/// order another viewer showed on a synthetic form.
const TOGGLE_ORDER: [&str; 2] = ["change", "click"];
/// After fields `names` took new values: each one's change, exit and validate scripts, then
@@ -890,11 +891,15 @@ pub(crate) fn on_changes(
let value = r.fields().get(name).map(|f| f.value.join("\n")).unwrap_or_default();
let clicked = r.clicked(name, &som, done.get(name).or_else(|| before.get(name)));
let steps: &[&str] = if clicked.is_some() { &TOGGLE_ORDER } else { &["change"] };
+ // A radio group's button now on runs each activity's scripts after the group's, and
+ // its exit scripts before the group's, as when leaving it.
+ let button = clicked.as_deref().filter(|b| *b != som);
for activity in steps.iter().copied().chain(["exit"]) {
- // A click's scripts are those of what was clicked; the others are the field's.
- let at = if activity == "click" { clicked.as_deref().unwrap_or(&som) } else { som.as_str() };
- for ev in r.events_of(at, activity) {
- r.run(&ev, &value)?;
+ let order = if activity == "exit" { [button, Some(som.as_str())] } else { [Some(som.as_str()), button] };
+ for at in order.into_iter().flatten() {
+ for ev in r.events_of(at, activity) {
+ r.run(&ev, &value)?;
+ }
}
}
for ev in r.events_of(&som, "validate") {
diff --git a/crates/ui-egui/tests/it/xfa.rs b/crates/ui-egui/tests/it/xfa.rs
index 9fb1422139..7e0b0e945d 100644
--- a/crates/ui-egui/tests/it/xfa.rs
+++ b/crates/ui-egui/tests/it/xfa.rs
@@ -154,7 +154,7 @@ fn xfa_check_box_and_radio_clicks_run_their_click_scripts_in_the_app() {
h.run_steps(1);
h.drop_at(p);
h.run_steps(4);
- assert!(log(&h).ends_with("no click;"), "{}", log(&h));
+ assert!(log(&h).ends_with("group click;no click;no exit;group exit;"), "{}", log(&h));
}
/// Clicking an XFA button in the app runs its click script: one adds a row, another shows its
diff --git a/crates/xfa/src/fixtures.rs b/crates/xfa/src/fixtures.rs
index f082defb7c..b1d2f79826 100644
--- a/crates/xfa/src/fixtures.rs
+++ b/crates/xfa/src/fixtures.rs
@@ -253,8 +253,11 @@ pub fn toggle_template() -> String {
- Y
- N
+ Y
+ N
+
+
+
@@ -265,8 +268,15 @@ pub fn toggle_template() -> String {
"##,
add(r#""change " + this.rawValue"#),
add(r#""click " + this.rawValue"#),
+ add(r#""yes change""#),
add(r#""yes click""#),
+ add(r#""yes exit""#),
+ add(r#""no change""#),
add(r#""no click""#),
+ add(r#""no exit""#),
+ add(r#""group change " + this.rawValue"#),
+ add(r#""group click""#),
+ add(r#""group exit""#),
add(r#""note click""#),
)
}
diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml
index 6aaec66d69..28ca3cb4c2 100644
--- a/parity/acrobat-features.toml
+++ b/parity/acrobat-features.toml
@@ -5297,7 +5297,7 @@ status = "partial"
commands = ["file.open"]
tools = ["doc_open", "doc_info", "form_fields", "form_fill", "js_run"]
evidence = ["crates/xfa/src/tests.rs::layout_places_captions_fields_and_sizes_containers_to_their_content", "crates/xfa/src/tests.rs::tables_break_across_pages_and_repeat_their_header_row", "crates/xfa/src/tests.rs::rendering_into_the_pdf_replaces_the_placeholder_page_and_adds_fields", "crates/engine/src/tests.rs::dynamic_xfa_forms_are_laid_out_on_open_filled_and_saved_incrementally", "crates/automation/tests/it/automation.rs::dynamic_xfa_forms_open_render_fill_and_save_through_tools", "crates/ui-egui/tests/it/xfa.rs::a_dynamic_xfa_form_is_laid_out_and_filled", "crates/xfa/src/tests.rs::nested_width_less_subforms_lay_out_in_polynomial_time", "crates/js/src/tests.rs::instance_managers_add_remove_and_count", "crates/xfa/src/tests.rs::the_form_tree_carries_values_presence_instances_and_the_events", "crates/engine/src/tests.rs::xfa_scripts_initialize_calculate_validate_toggle_and_add_rows", "crates/engine/src/tests.rs::xfa_date_arithmetic_reads_the_date_as_its_display_picture_shows_it", "crates/automation/tests/it/automation.rs::xfa_scripts_run_for_buttons_and_field_changes_through_tools", "crates/ui-egui/tests/it/xfa.rs::xfa_buttons_run_their_scripts_in_the_app", "crates/engine/src/tests.rs::hostile_xfa_open_scripts_are_merged_capped_kept_from_printing_and_noted", "crates/engine/src/tests.rs::runaway_xfa_calculations_at_open_end_quickly_with_a_report", "crates/ui-egui/tests/it/xfa.rs::a_form_whose_scripts_were_turned_off_at_open_says_so", "crates/ui-egui/tests/it/xfa.rs::scripts_turned_off_by_a_click_bring_a_closed_notice_bar_back", "crates/automation/tests/it/automation.rs::doc_info_says_when_a_runaway_script_turned_the_forms_scripts_off", "crates/xfa/src/tests.rs::the_live_form_of_nested_repeating_subforms_stops_at_its_node_budget", "crates/xfa/src/tests.rs::data_ops_of_one_event_are_one_datasets_rewrite", "crates/xfa/src/tests.rs::choice_lists_signatures_passwords_and_pictures_become_fields_and_images", "crates/xfa/src/tests.rs::choice_values_come_from_the_data_as_saved_values_and_several_for_lists", "crates/xfa/src/tests.rs::pictures_are_sized_from_their_headers_and_hostile_ones_are_refused_unallocated", "crates/engine/src/tests.rs::xfa_choice_lists_signature_and_picture_fields_open_fill_script_and_save", "crates/xfa/src/tests.rs::repeating_subforms_inside_positioned_content_get_their_instances", "crates/engine/src/tests.rs::xfa_rows_in_areas_are_laid_out_read_calculated_and_written_where_adobe_binds_them", "crates/xfa/src/tests.rs::page_area_without_occur_serves_every_body_page", "apps/pdfcraft-cli/tests/it/xfa.rs::info_reports_the_laid_out_pages_and_fields", "apps/pdfcraft-cli/tests/it/xfa.rs::text_reads_the_layout_including_a_page_absent_from_the_placeholder", "apps/pdfcraft-cli/tests/it/xfa.rs::render_matches_the_engine_layout_on_the_second_page", "apps/pdfcraft-cli/tests/it/xfa.rs::a_laid_out_form_keeps_the_original_copy_permissions", "crates/engine/src/tests.rs::filling_growable_xfa_text_reflows_and_undo_restores_the_layout", "crates/engine/src/tests.rs::xfa_text_growth_refreshes_widget_geometry_but_fixed_height_fields_keep_their_widgets", "crates/automation/tests/it/automation.rs::growable_xfa_text_paginates_after_fill_save_and_print", "crates/engine/src/tests.rs::an_xfa_script_that_fails_partway_keeps_what_it_changed_before_the_error", "crates/engine/src/tests.rs::repeated_xfa_print_buttons_run_their_click_script", "crates/automation/tests/it/automation.rs::repeated_xfa_print_buttons_work_through_tools_and_after_reopen", "crates/xfa/src/tests.rs::rich_text_max_length_reaches_the_field_and_layout", "crates/automation/tests/it/automation.rs::xfa_rich_text_max_length_is_reported_and_enforced_through_tools", "crates/xfa/src/tests.rs::bmp_and_tiff_pictures_are_decoded_and_drawn", "crates/engine/src/tests.rs::active_xfa_does_not_run_pdf_container_scripts_but_keeps_requested_alerts", "crates/engine/src/tests.rs::active_xfa_without_template_scripts_does_not_initialize_pdf_fallback_scripts", "crates/engine/src/tests.rs::inactive_xfa_and_ordinary_pdfs_keep_document_helpers_and_alerts", "crates/automation/tests/it/automation.rs::active_xfa_skips_container_fallback_scripts_after_save_and_reopen", "crates/xfa/src/tests.rs::laying_a_form_out_takes_off_the_usage_rights_it_voids", "crates/engine/src/tests.rs::a_dynamic_xfa_form_is_saved_without_the_usage_rights_its_layout_voided", "crates/xfa/src/tests.rs::faces_measure_text_at_their_standard_14_widths", "crates/xfa/src/tests.rs::rich_text_links_keep_their_address", "crates/xfa/src/tests.rs::links_in_rich_text_become_link_annotations_one_per_line", "crates/xfa/src/tests.rs::a_links_pieces_share_one_address", "crates/xfa/src/tests.rs::a_rule_between_two_pieces_of_a_link_keeps_them_apart", "crates/xfa/src/tests.rs::links_to_anything_but_web_and_email_addresses_stay_plain_text", "crates/automation/tests/it/automation.rs::links_in_xfa_rich_text_are_listed_through_tools", "crates/xfa/src/tests.rs::rounded_corners_make_a_border_one_rounded_shape", "crates/xfa/src/tests.rs::a_rounded_box_cut_by_a_page_break_keeps_its_corners_on_each_page", "crates/xfa/src/tests.rs::rounded_boxes_are_written_as_curved_paths", "crates/xfa/src/tests.rs::a_flowed_subform_is_drawn_with_its_border_under_its_content", "crates/xfa/src/tests.rs::a_check_box_sits_where_its_margins_caption_and_alignment_put_it", "crates/xfa/src/tests.rs::a_check_box_caption_without_a_reserve_takes_the_rest_of_the_field", "crates/xfa/src/tests.rs::a_radio_button_sits_where_a_check_box_would", "crates/xfa/src/tests.rs::a_check_box_caption_without_a_reserve_is_measured_as_it_is_drawn", "crates/engine/src/tests.rs::xfa_check_box_and_radio_button_clicks_run_their_click_scripts", "crates/automation/tests/it/automation.rs::xfa_check_box_and_radio_clicks_run_through_form_fill", "crates/ui-egui/tests/it/xfa.rs::xfa_check_box_and_radio_clicks_run_their_click_scripts_in_the_app"]
-notes = "Active XFA layout skips PDF-container document-script initialization for the Acrobat console/field context, so fallback-viewer scripts do not run there. Scripts remain in the file/listing; explicit console/field and XFA alerts still run. Ordinary PDF, static XFA and unlaid-out shells keep document scripts; static-conversion undo restores the XFA policy. Changed growable multiline text (no fixed h) reflows from final datasets after edits, with or without scripts; pages/widgets refresh and undo/redo, save/reopen and print retain all text. Oversized text still uses the existing read-only page-text fallback with a warning; fixed-height fields do not reflow. Repeated page-master buttons resolve their own PDF field to the shared XFA click script; the numPages-based print script requests printing from every copy, including after save/reopen (#2572). Rich-text exData/maxLength is carried into AcroForm MaxLen, reported by form_fields and enforced by form_fill (Unicode characters); limits and accepted values survive save/reopen (#2570). laid out from the template on open by the xfa crate (positioned, tb, lr-tb, table/row, page masters (a page area with no occur repeats without limit, one with occur max=1 is used once, one with occur min=1 the body never reached gets a page after the body, as Acrobat Pro does on a synthetic form), breaks, repeated header rows, borders and fills of flowed subforms (a page break between their children gives each page's part a closed border, the margins repeated at the cut, as measured on a synthetic form in another viewer, and a child's own page break breaks them the same way; one holding an item that doesn't fit on its page, cut across pages or placed past the content area's bottom, is drawn without its border, with a layout warning), captions, rounded and inverted border corners, rich text (its http, https and mailto links clickable), JPEG/PNG/GIF/BMP/TIFF images) into real pages and AcroForm fields (text, password, date with AFDate formats, check boxes and radio groups (each box placed by its field's margins, caption and paragraph alignment as measured on two synthetic forms in another viewer: with no caption at the right of the content area, beside a reserved caption where the alignment puts it, and a caption without a reserve taking the rest of the field; a check box's own margin larger than the box draws a bigger box there, which isn't copied), drop-downs and list boxes with shown/saved item pairs and multi-select, signature fields, image fields showing their picture (pictures decoded once per document, at most 20 million pixels, and reused across re-layouts), buttons with reset/print/save/URL), filled from the datasets packet (including rows another viewer added), saved as an incremental revision with the values merged into the datasets so Adobe's viewers show them; usage rights the form carried (/Perms /UR3) are taken off with a note, as the layout voids them and a form with void usage rights opens with every field locked; doc_info reports xfa_layout. CLI info reports the laid-out page/field counts and dimensions while retaining the input file size and raw counts as pdf_pages/acroform_fields; text and render use those pages too, preserving copy permissions and leaving the source file unchanged (#1645). XFA JavaScript and FormCalc (form.xfa-formcalc) run in the js crate's XFA object model (xfa.form, SOM resolution, rawValue, formattedValue in a date display picture's pattern (number and text display pictures still give the raw value), presence, access, instance managers, xfa.host, xfa.layout, xfa.event): initialize and calculate on open, exit, validate and calculate after a field changes, click for buttons (through js_run and the app) and for check boxes and radio buttons each time a click changes them, after their change scripts, a radio button running its own (in the app and through form_fill), with rows added and removed, subforms shown and hidden, and the form laid out again, all as one undo step and kept in the file. All the scripts of one event run on one thread, each in a fresh context on the form as the engine holds it then (nothing shared between scripts; the live form kept up to date in place for values, rebuilt only when the structure changed), so hundreds of calculations run within the open budget. Hostile scripts are bounded per event (merged and capped effects, messages and console lines, lower loop limits and a time budget on open and calculate, one datasets rewrite per event, print/save/links/focus from clicks only, a runaway script abandoned and the form's scripts turned off, which the app says in a toast and on the notice bar, with a button to the JavaScript console, and doc_info reports as xfa_scripts_off) and what open-time scripts changed is noted. A script that fails partway keeps what it changed before the error, as JavaScript does (forms often trip over an object an earlier version had after their first lines did the work). Missing: a page area's relevant=\"-print\" (on a synthetic form Acrobat still prints the page but leaves it blank; PdfCraft prints its content, #2574); a page break before the first section (Acrobat opens an empty body page first when the first section has breakBefore targetType=pageArea, with or without startNew, as seen on synthetic forms; PdfCraft skips a break on an empty page and lays out one page fewer, #2574); loops inside nested calls are only stopped by abandoning their thread, and script memory is not capped; the change event per keystroke; xfa.template, connections and data descriptions; a hidden instance of a repeating subform hides them all; barcodes are drawn as their text, not bars; keep rules; text is measured at the exact standard-14 widths of the face it is drawn in (bold, italic and Times included), not in the template's own typefaces, and Acrobat fidelity is eyeballed on real forms, not measured (#60)"
+notes = "Active XFA layout skips PDF-container document-script initialization for the Acrobat console/field context, so fallback-viewer scripts do not run there. Scripts remain in the file/listing; explicit console/field and XFA alerts still run. Ordinary PDF, static XFA and unlaid-out shells keep document scripts; static-conversion undo restores the XFA policy. Changed growable multiline text (no fixed h) reflows from final datasets after edits, with or without scripts; pages/widgets refresh and undo/redo, save/reopen and print retain all text. Oversized text still uses the existing read-only page-text fallback with a warning; fixed-height fields do not reflow. Repeated page-master buttons resolve their own PDF field to the shared XFA click script; the numPages-based print script requests printing from every copy, including after save/reopen (#2572). Rich-text exData/maxLength is carried into AcroForm MaxLen, reported by form_fields and enforced by form_fill (Unicode characters); limits and accepted values survive save/reopen (#2570). laid out from the template on open by the xfa crate (positioned, tb, lr-tb, table/row, page masters (a page area with no occur repeats without limit, one with occur max=1 is used once, one with occur min=1 the body never reached gets a page after the body, as Acrobat Pro does on a synthetic form), breaks, repeated header rows, borders and fills of flowed subforms (a page break between their children gives each page's part a closed border, the margins repeated at the cut, as measured on a synthetic form in another viewer, and a child's own page break breaks them the same way; one holding an item that doesn't fit on its page, cut across pages or placed past the content area's bottom, is drawn without its border, with a layout warning), captions, rounded and inverted border corners, rich text (its http, https and mailto links clickable), JPEG/PNG/GIF/BMP/TIFF images) into real pages and AcroForm fields (text, password, date with AFDate formats, check boxes and radio groups (each box placed by its field's margins, caption and paragraph alignment as measured on two synthetic forms in another viewer: with no caption at the right of the content area, beside a reserved caption where the alignment puts it, and a caption without a reserve taking the rest of the field; a check box's own margin larger than the box draws a bigger box there, which isn't copied), drop-downs and list boxes with shown/saved item pairs and multi-select, signature fields, image fields showing their picture (pictures decoded once per document, at most 20 million pixels, and reused across re-layouts), buttons with reset/print/save/URL), filled from the datasets packet (including rows another viewer added), saved as an incremental revision with the values merged into the datasets so Adobe's viewers show them; usage rights the form carried (/Perms /UR3) are taken off with a note, as the layout voids them and a form with void usage rights opens with every field locked; doc_info reports xfa_layout. CLI info reports the laid-out page/field counts and dimensions while retaining the input file size and raw counts as pdf_pages/acroform_fields; text and render use those pages too, preserving copy permissions and leaving the source file unchanged (#1645). XFA JavaScript and FormCalc (form.xfa-formcalc) run in the js crate's XFA object model (xfa.form, SOM resolution, rawValue, formattedValue in a date display picture's pattern (number and text display pictures still give the raw value), presence, access, instance managers, xfa.host, xfa.layout, xfa.event): initialize and calculate on open, exit, validate and calculate after a field changes, click for buttons (through js_run and the app) and for check boxes and radio buttons each time a click changes them, after their change scripts, a radio group's change and click scripts running before those of the button now on, in the order another viewer runs them on a synthetic form (in the app and through form_fill), with rows added and removed, subforms shown and hidden, and the form laid out again, all as one undo step and kept in the file. All the scripts of one event run on one thread, each in a fresh context on the form as the engine holds it then (nothing shared between scripts; the live form kept up to date in place for values, rebuilt only when the structure changed), so hundreds of calculations run within the open budget. Hostile scripts are bounded per event (merged and capped effects, messages and console lines, lower loop limits and a time budget on open and calculate, one datasets rewrite per event, print/save/links/focus from clicks only, a runaway script abandoned and the form's scripts turned off, which the app says in a toast and on the notice bar, with a button to the JavaScript console, and doc_info reports as xfa_scripts_off) and what open-time scripts changed is noted. A script that fails partway keeps what it changed before the error, as JavaScript does (forms often trip over an object an earlier version had after their first lines did the work). Missing: a page area's relevant=\"-print\" (on a synthetic form Acrobat still prints the page but leaves it blank; PdfCraft prints its content, #2574); a page break before the first section (Acrobat opens an empty body page first when the first section has breakBefore targetType=pageArea, with or without startNew, as seen on synthetic forms; PdfCraft skips a break on an empty page and lays out one page fewer, #2574); loops inside nested calls are only stopped by abandoning their thread, and script memory is not capped; the change event per keystroke; a check box's or radio button's exit scripts run after each click, where another viewer runs them once, when it loses the focus; xfa.template, connections and data descriptions; a hidden instance of a repeating subform hides them all; barcodes are drawn as their text, not bars; keep rules; text is measured at the exact standard-14 widths of the face it is drawn in (bold, italic and Times included), not in the template's own typefaces, and Acrobat fidelity is eyeballed on real forms, not measured (#60)"
[[feature]]
id = "form.xfa-formcalc"
From e8d3f2600128746be4ae00841156947c8ae39ecb Mon Sep 17 00:00:00 2001
From: Eric Kaden <608341+EricKaden@users.noreply.github.com>
Date: Mon, 9 Nov 2026 14:21:44 -0500
Subject: [PATCH 08/10] A radio button's exit that its click ran is not run
again on leaving
---
crates/engine/src/tests.rs | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs
index f3f34088a3..3eb18ad305 100644
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@ -7427,8 +7427,8 @@ fn a_widget_the_field_doesnt_have_runs_no_focus_scripts() {
/// Each radio button of a group is a field of its own: reaching the second button runs its
/// enter script, reaching the first (which has none) runs nothing. Choosing the button changes
-/// the group's value, which runs the group's scripts, not the button's: leaving the button
-/// still runs its exit.
+/// the group's value, which runs the group's scripts and the new button's (its exit among them,
+/// as when leaving it), so leaving the button does not run that exit a second time.
#[test]
fn a_radio_buttons_own_focus_scripts_run() {
use crate::js::FieldFocus::{Enter, Exit};
@@ -7440,7 +7440,8 @@ fn a_radio_buttons_own_focus_scripts_run() {
assert!(!s.field_focus(id, &group, 2, Enter).unwrap(), "there is no third button");
assert_eq!(field_text(&s, id, "picks"), "1");
s.apply(id, Edit::SetFieldValue { name: group.clone(), value: FieldValue::Radio(Some("L".into())) }).unwrap();
- assert!(s.field_focus(id, &group, 1, Exit).unwrap(), "the button's exit runs on leaving it");
+ assert_eq!(field_text(&s, id, "drops"), "1", "the click ran the button's exit");
+ assert!(!s.field_focus(id, &group, 1, Exit).unwrap(), "that exit is not run again on leaving");
assert_eq!(field_text(&s, id, "drops"), "1");
}
From 1c2a179a62171fa8e4d5497ad4b41f12acca1940 Mon Sep 17 00:00:00 2001
From: FredApps <153173854+FredApps@users.noreply.github.com>
Date: Thu, 26 Nov 2026 22:18:15 +0700
Subject: [PATCH 09/10] Fit the landed changes together: the click test expects
main's FocusField request
---
crates/engine/src/tests.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs
index dd35d6821e..d09aadfc62 100644
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@ -9133,7 +9133,7 @@ fn xfa_check_box_and_radio_button_clicks_run_their_click_scripts() {
assert_eq!(log(&s), "change 1;click 1;", "change, then click, each seeing the new value");
let out = s.take_js_output(id);
assert_eq!(out.alerts, [crate::js::Message::plain("Agreed")]);
- assert!(out.requests.iter().any(|r| matches!(r, pdfcraft_js::Request::Focus(n) if n == "note")), "a click may move the focus: {out:?}");
+ assert!(out.requests.iter().any(|r| matches!(r, pdfcraft_js::Request::FocusField { name, .. } if name == "note")), "a click may move the focus: {out:?}");
s.apply(id, Edit::SetFieldValue { name: "agree".into(), value: FieldValue::Check(false) }).unwrap();
assert_eq!(log(&s), "change 1;click 1;change 0;click 0;", "turning it off is a click too");
// One undo step takes back the click and what its scripts did.
From 8e8019a742c3a8428d18b8728b7cf6911c7d6e80 Mon Sep 17 00:00:00 2001
From: FredApps <153173854+FredApps@users.noreply.github.com>
Date: Thu, 26 Nov 2026 16:49:37 +0100
Subject: [PATCH 10/10] Format the click test's focus assertion
---
crates/engine/src/tests.rs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs
index d09aadfc62..08f10c190a 100644
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@ -9133,7 +9133,10 @@ fn xfa_check_box_and_radio_button_clicks_run_their_click_scripts() {
assert_eq!(log(&s), "change 1;click 1;", "change, then click, each seeing the new value");
let out = s.take_js_output(id);
assert_eq!(out.alerts, [crate::js::Message::plain("Agreed")]);
- assert!(out.requests.iter().any(|r| matches!(r, pdfcraft_js::Request::FocusField { name, .. } if name == "note")), "a click may move the focus: {out:?}");
+ assert!(
+ out.requests.iter().any(|r| matches!(r, pdfcraft_js::Request::FocusField { name, .. } if name == "note")),
+ "a click may move the focus: {out:?}"
+ );
s.apply(id, Edit::SetFieldValue { name: "agree".into(), value: FieldValue::Check(false) }).unwrap();
assert_eq!(log(&s), "change 1;click 1;change 0;click 0;", "turning it off is a click too");
// One undo step takes back the click and what its scripts did.