mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-19 02:26:48 +00:00
M12: a widget index the field doesn't have runs no focus scripts
widget_som fell back to the field's own SOM path for an index out of range, so for a radio field it ran the group's scripts. It now returns None unless the field has that widget.
This commit is contained in:
1 parent
0a6d8fe775
commit
aad694b6ad
2 files changed
+18
-2
No files matched your search
@@ -5266,6 +5266,19 @@ fn focus_scripts_that_change_nothing_leave_the_document_clean() {
|
||||
assert!(!s.get(id).unwrap().dirty);
|
||||
}
|
||||
|
||||
/// A widget the field doesn't have gains or loses no focus: no script runs, rather than the
|
||||
/// field's own.
|
||||
#[test]
|
||||
fn a_widget_the_field_doesnt_have_runs_no_focus_scripts() {
|
||||
use crate::js::FieldFocus::{Enter, Exit};
|
||||
let mut s = Session::new();
|
||||
let id = s.open("form.pdf", None, focus_form(), None).expect("opens");
|
||||
assert!(!s.field_focus(id, "probe", 3, Enter).unwrap(), "probe has one widget");
|
||||
assert!(!s.field_focus(id, "probe", usize::MAX, Exit).unwrap());
|
||||
assert_eq!((field_text(&s, id, "enters"), field_text(&s, id, "exits")), ("0".into(), "0".into()));
|
||||
assert!(!s.get(id).unwrap().dirty);
|
||||
}
|
||||
|
||||
/// 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
|
||||
|
||||
@@ -936,13 +936,16 @@ pub(crate) fn on_focus(doc: &mut pdfcraft_cos::Document, tpl: &Template, som: &s
|
||||
}
|
||||
|
||||
/// The SOM path of widget `widget` of field `field`: each radio button of a group has its own,
|
||||
/// and a field's copies on several pages share one.
|
||||
/// and a field's copies on several pages share one. `None` when the field has no widget
|
||||
/// `widget`: the field's own path is only for a widget that records none, so a widget index
|
||||
/// out of range never reaches the field (for a radio field, the group).
|
||||
pub(crate) fn widget_som(doc: &pdfcraft_cos::Document, field: &pdfcraft_forms::Field, widget: usize) -> Option<String> {
|
||||
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())
|
||||
};
|
||||
field.widgets.get(widget).and_then(|w| som_of(w.obj)).or_else(|| som_of(field.obj))
|
||||
let w = field.widgets.get(widget)?;
|
||||
som_of(w.obj).or_else(|| som_of(field.obj))
|
||||
}
|
||||
|
||||
/// Does the live form give SOM path `som` an `activity` script?
|
||||
|
||||
Reference in new issue
Block a user