mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-10 14:41:51 +00:00
M12: a radio button that must be chosen makes its group required even when an earlier button made the group
This commit is contained in:
+11
-1
@@ -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"));
|
||||
|
||||
@@ -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 (`<validate nullTest="error">`) 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() {
|
||||
<exclGroup name="optional" layout="lr-tb">
|
||||
<field name="a" w="1in" h="0.3in"><ui><checkButton shape="round"/></ui><items><text>A</text></items></field>
|
||||
</exclGroup>
|
||||
<exclGroup name="second" layout="lr-tb">
|
||||
<field name="b" w="1in" h="0.3in"><ui><checkButton shape="round"/></ui><items><text>B</text></items></field>
|
||||
<field name="c" w="1in" h="0.3in"><ui><checkButton shape="round"/></ui><items><text>C</text></items><validate nullTest="error"/></field>
|
||||
</exclGroup>
|
||||
</subform></template></xdp:xdp>"##;
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user