Skip to content

Commit f720e9b

Browse files
committed
Custom toolbar radio button
1 parent 418308e commit f720e9b

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import type { Instance } from "@nutrient-sdk/viewer";
2+
import { baseOptions } from "../../shared/base-options";
3+
4+
let instance: Instance | null = null;
5+
6+
const item = {
7+
type: "custom",
8+
id: "add-radio-group",
9+
title: "Add Radio Group",
10+
onPress: async () => {
11+
const radioWidget1 = new window.NutrientViewer.Annotations.WidgetAnnotation(
12+
{
13+
id: window.NutrientViewer.generateInstantId(),
14+
pageIndex: 0,
15+
formFieldName: "MyFormField",
16+
boundingBox: new window.NutrientViewer.Geometry.Rect({
17+
left: 100,
18+
top: 100,
19+
width: 20,
20+
height: 20,
21+
}),
22+
},
23+
);
24+
const radioWidget2 = new window.NutrientViewer.Annotations.WidgetAnnotation(
25+
{
26+
id: window.NutrientViewer.generateInstantId(),
27+
pageIndex: 0,
28+
formFieldName: "MyFormField",
29+
boundingBox: new window.NutrientViewer.Geometry.Rect({
30+
left: 130,
31+
top: 100,
32+
width: 20,
33+
height: 20,
34+
}),
35+
},
36+
);
37+
const formField = new window.NutrientViewer.FormFields.RadioButtonFormField(
38+
{
39+
name: "MyFormField",
40+
annotationIds: new window.NutrientViewer.Immutable.List([
41+
radioWidget1.id,
42+
radioWidget2.id,
43+
]),
44+
options: new window.NutrientViewer.Immutable.List([
45+
new window.NutrientViewer.FormOption({
46+
label: "Option 1",
47+
value: "1",
48+
}),
49+
new window.NutrientViewer.FormOption({
50+
label: "Option 2",
51+
value: "2",
52+
}),
53+
]),
54+
defaultValue: "1",
55+
},
56+
);
57+
await instance!.create([radioWidget1, radioWidget2, formField]);
58+
},
59+
};
60+
61+
window.NutrientViewer.load({
62+
...baseOptions,
63+
theme: window.NutrientViewer.Theme.DARK,
64+
toolbarItems: [
65+
...window.NutrientViewer.defaultToolbarItems,
66+
{ type: "form-creator" },
67+
],
68+
}).then((_instance: Instance) => {
69+
instance = _instance;
70+
instance.setToolbarItems((items) => [...items, item]);
71+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: forms
3+
title: Add Grouped Radio Buttons with Custom Toolbar Button
4+
description: Create a custom toolbar item that programmatically places pre-grouped radio buttons with a single click, avoiding manual renaming.
5+
keywords: [forms, radio-button, custom-toolbar, toolbar-item, widget, form-field, radio-group, grouped radio-buttons]
6+
---
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[InternetShortcut]
2+
URL=https://playground.pspdfkit.com/?p=eyJ2IjoxLCJjc3MiOiIvKiBBZGQgeW91ciBDU1MgaGVyZSAqL1xuIiwic2V0dGluZ3MiOnsiZmlsZU5hbWUiOiJiYXNpYy5wZGYifSwianMiOiJsZXQgaW5zdGFuY2UgPSBudWxsO1xuXG5jb25zdCBpdGVtID0ge1xuICB0eXBlOiBcImN1c3RvbVwiLFxuICBpZDogXCJhZGQtcmFkaW8tZ3JvdXBcIixcbiAgdGl0bGU6IFwiQWRkIFJhZGlvIEdyb3VwXCIsXG4gIG9uUHJlc3M6IGFzeW5jICgpID0%252BIHtcbiAgICBjb25zdCByYWRpb1dpZGdldDEgPSBuZXcgTnV0cmllbnRWaWV3ZXIuQW5ub3RhdGlvbnMuV2lkZ2V0QW5ub3RhdGlvbih7XG4gIGlkOiBOdXRyaWVudFZpZXdlci5nZW5lcmF0ZUluc3RhbnRJZCgpLFxuICBwYWdlSW5kZXg6IDAsXG4gIGZvcm1GaWVsZE5hbWU6IFwiTXlGb3JtRmllbGRcIixcbiAgYm91bmRpbmdCb3g6IG5ldyBOdXRyaWVudFZpZXdlci5HZW9tZXRyeS5SZWN0KHtcbiAgICBsZWZ0OiAxMDAsXG4gICAgdG9wOiAxMDAsXG4gICAgd2lkdGg6IDIwLFxuICAgIGhlaWdodDogMjB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