Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions playground/forms/custom-toolbar-radio-button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import type { Instance } from "@nutrient-sdk/viewer";
import { baseOptions } from "../../shared/base-options";

let instance: Instance | null = null;

const item = {
type: "custom",
id: "add-radio-group",
title: "Add Radio Group",
onPress: async () => {
const radioWidget1 = new window.NutrientViewer.Annotations.WidgetAnnotation(
{
id: window.NutrientViewer.generateInstantId(),
pageIndex: 0,
formFieldName: "MyFormField",
boundingBox: new window.NutrientViewer.Geometry.Rect({
left: 100,
top: 100,
width: 20,
height: 20,
}),
},
);

const radioWidget2 = new window.NutrientViewer.Annotations.WidgetAnnotation(
{
id: window.NutrientViewer.generateInstantId(),
pageIndex: 0,
formFieldName: "MyFormField",
boundingBox: new window.NutrientViewer.Geometry.Rect({
left: 130,
top: 100,
width: 20,
height: 20,
}),
},
);

const formField = new window.NutrientViewer.FormFields.RadioButtonFormField(
{
name: "MyFormField",
annotationIds: new window.NutrientViewer.Immutable.List([
radioWidget1.id,
radioWidget2.id,
]),
options: new window.NutrientViewer.Immutable.List([
new window.NutrientViewer.FormOption({
label: "Option 1",
value: "1",
}),
new window.NutrientViewer.FormOption({
label: "Option 2",
value: "2",
}),
]),
defaultValue: "1",
},
);

await instance?.create([radioWidget1, radioWidget2, formField]);
},
};

window.NutrientViewer.load({
...baseOptions,
theme: window.NutrientViewer.Theme.DARK,
toolbarItems: [
...window.NutrientViewer.defaultToolbarItems,
{ type: "form-creator" },
],
}).then((_instance: Instance) => {
instance = _instance;
instance.setToolbarItems((items) => [...items, item]);
});
7 changes: 7 additions & 0 deletions playground/forms/custom-toolbar-radio-button/playground.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
category: forms
title: Add Grouped Radio Buttons with Custom Toolbar Button
description: Create a custom toolbar item that programmatically places grouped radio buttons with a single click, avoiding manual renaming.
keywords: [forms, radio-button, custom-toolbar, toolbar-item, widget, form-field, radio-group, grouped radio-buttons]
---

2 changes: 2 additions & 0 deletions playground/forms/custom-toolbar-radio-button/playground.url
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[InternetShortcut]
URL=https://playground.pspdfkit.com/?p=eyJ2IjoxLCJjc3MiOiIvKiBBZGQgeW91ciBDU1MgaGVyZSAqL1xuIiwic2V0dGluZ3MiOnsiZmlsZU5hbWUiOiJiYXNpYy5wZGYifSwianMiOiJsZXQgaW5zdGFuY2UgPSBudWxsO1xuXG5jb25zdCBpdGVtID0ge1xuICB0eXBlOiBcImN1c3RvbVwiLFxuICBpZDogXCJhZGQtcmFkaW8tZ3JvdXBcIixcbiAgdGl0bGU6IFwiQWRkIFJhZGlvIEdyb3VwXCIsXG4gIG9uUHJlc3M6IGFzeW5jICgpID0%252BIHtcbiAgICBjb25zdCByYWRpb1dpZGdldDEgPSBuZXcgTnV0cmllbnRWaWV3ZXIuQW5ub3RhdGlvbnMuV2lkZ2V0QW5ub3RhdGlvbih7XG4gIGlkOiBOdXRyaWVudFZpZXdlci5nZW5lcmF0ZUluc3RhbnRJZCgpLFxuICBwYWdlSW5kZXg6IDAsXG4gIGZvcm1GaWVsZE5hbWU6IFwiTXlGb3JtRmllbGRcIixcbiAgYm91bmRpbmdCb3g6IG5ldyBOdXRyaWVudFZpZXdlci5HZW9tZXRyeS5SZWN0KHtcbiAgICBsZWZ0OiAxMDAsXG4gICAgdG9wOiAxMDAsXG4gICAgd2lkdGg6IDIwLFxuICAgIGhlaWdodDogMjBcbiAgfSlcbn0pO1xuY29uc3QgcmFkaW9XaWRnZXQyID0gbmV3IE51dHJpZW50Vmlld2VyLkFubm90YXRpb25zLldpZGdldEFubm90YXRpb24oe1xuICBpZDogTnV0cmllbnRWaWV3ZXIuZ2VuZXJhdGVJbnN0YW50SWQoKSxcbiAgcGFn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