Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with button JavaScript execution #19398

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
97 changes: 53 additions & 44 deletions src/scripting_api/initialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,57 +71,66 @@ function initSandbox(params) {
const appObjects = app._objects;

if (data.objects) {
const annotations = [];

for (const [name, objs] of Object.entries(data.objects)) {
annotations.length = 0;
let container = null;

for (const obj of objs) {
if (obj.type !== "") {
annotations.push(obj);
} else {
container = obj;
// Separate annotations and container
const annotations = objs.filter(obj => obj.type !== "");
const container = objs.find(obj => obj.type === "");

// Process each annotation (button, checkbox, etc.)
for (const obj of annotations) {
obj.send = send; // Assign the send function to each annotation
obj.globalEval = globalEval;
obj.doc = _document;
obj.fieldPath = name;
obj.appObjects = appObjects;

// Handle siblings (if any)
const otherFields = annotations.filter(x => x !== obj);
if (otherFields.length > 0) {
obj.siblings = otherFields.map(x => x.id);
}
}

let obj = container;
if (annotations.length > 0) {
obj = annotations[0];
obj.send = send;
}

obj.globalEval = globalEval;
obj.doc = _document;
obj.fieldPath = name;
obj.appObjects = appObjects;

const otherFields = annotations.slice(1);

let field;
switch (obj.type) {
case "radiobutton": {
field = new RadioButtonField(otherFields, obj);
break;
}
case "checkbox": {
field = new CheckboxField(otherFields, obj);
break;
// Create a Field instance based on the type
let field;
switch (obj.type) {
case "radiobutton":
field = new RadioButtonField(
otherFields.map(x => x.id),
obj
); // Pass sibling IDs
break;
case "checkbox":
field = new CheckboxField(
otherFields.map(x => x.id),
obj
); // Pass sibling IDs
break;
default:
field = new Field(obj);
}
default:
if (otherFields.length > 0) {
obj.siblings = otherFields.map(x => x.id);
}
field = new Field(obj);
}

const wrapped = new Proxy(field, proxyHandler);
const _object = { obj: field, wrapped };
doc._addField(name, _object);
for (const object of objs) {
appObjects[object.id] = _object;
// Wrap the field in a Proxy and add it to doc and appObjects
const wrapped = new Proxy(field, proxyHandler);
const _object = { obj: field, wrapped };
doc._addField(name, _object);
appObjects[obj.id] = _object;
}

// Handle the container (if it exists)
if (container) {
container.send = send;
container.globalEval = globalEval;
container.doc = _document;
container.fieldPath = name;
container.appObjects = appObjects;

// Create a Field instance for the container
const field = new Field(container);
const wrapped = new Proxy(field, proxyHandler);
const _object = { obj: field, wrapped };

// Add the container to doc and appObjects
doc._addField(name, _object);
appObjects[container.id] = _object;
}
}
Expand Down