From 4e0cff1d613d3a300c31046fde3c550375806bd3 Mon Sep 17 00:00:00 2001 From: gqcorneby <185756521+gqcorneby@users.noreply.github.com> Date: Tue, 14 Oct 2025 15:12:42 +0800 Subject: [PATCH 01/13] allow and run script tags --- .../custom-form/custom-form.jsx | 27 ++++++++++++++----- .../custom-form/parse-html-to-react.jsx | 5 ++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/data-workspace/custom-form/custom-form.jsx b/src/data-workspace/custom-form/custom-form.jsx index afe96b0306..287890cf49 100644 --- a/src/data-workspace/custom-form/custom-form.jsx +++ b/src/data-workspace/custom-form/custom-form.jsx @@ -1,15 +1,10 @@ import PropTypes from 'prop-types' -import React from 'react' +import React, { useEffect, useRef } from 'react' import useCustomForm from '../../custom-forms/use-custom-form.js' import { useMetadata } from '../../shared/index.js' import styles from './custom-form.module.css' import { parseHtmlToReact } from './parse-html-to-react.jsx' -/** - * This implementation of custom forms only supports custom - * HTML and CSS. It does not support custom logic (JavaScript). - * For more info see ./docs/custom-froms.md - */ export const CustomForm = ({ dataSet }) => { const { data: customForm } = useCustomForm({ id: dataSet.dataEntryForm.id, @@ -17,8 +12,26 @@ export const CustomForm = ({ dataSet }) => { }) const { data: metadata } = useMetadata() + const containerRef = useRef(null) + + useEffect(() => { + if (containerRef.current) { + const scripts = containerRef.current.querySelectorAll('script') + + scripts.forEach((oldScript) => { + const newScript = document.createElement('script') + + for (const attr of oldScript.attributes) { + newScript.setAttribute(attr.name, attr.value) + } + newScript.text = oldScript.innerHTML + oldScript.parentNode.replaceChild(newScript, oldScript) + }) + } + }, [customForm]) + return customForm ? ( -