Hello,
I am currently working on implementing “Filling out the form” using React.
(ONLYOFFICE Api Documentation - External access to the document editing)
import { DocumentEditor } from "@onlyoffice/document-editor-react";
import React, { useState } from "react";
function App() {
var connector = "";
const [contentControls, setContentControls] = useState([]);
var onDocumentReady = function () {
try {
var docEditor = window.DocEditor.instances["oformEditor"];
connector = docEditor.createConnector();
getAllContentControls();
connector.attachEvent("onChangeContentControl", onChangeContentControl);
} catch (err) {
console.error(err);
}
};
const getAllContentControls = () => {
connector.executeMethod("GetAllContentControls", null, function (data) {
setTimeout(function () {
for (let i = 0; i < data.length; i++) {
connector.executeMethod("GetFormValue", data[i].InternalId, function (value) {
data[i].Value = value ? value : "";
if (data.length - 1 === i) {
setContentControls(data);
}
})
}
}, 3000 * 10);
})
}
const onChangeContentControl = (data) => {
console.log("check onChangeContentControl");
window.Asc.plugin.executeMethod("GetFormsByTag", data.Tag, function (data) {
console.log("check GetFormsByTag");
for (var i = 0; i < data.length; i++) {
if (data[i].InternalId != null) {
connector.executeMethod("SelectContentControl", [data[i].InternalId]);
break;
}
}
});
connector.executeMethod("GetFormValue", data.DocumentId, data.FormId, function (value) {
data.Value = value ? value : "";
setContentControls(data);
});
}
const onDocumentStateChange = (e) => {
console.log("server connect ", e.data);
}
return (
<div className="App" >
<div>
<DocumentEditor
id="oformEditor"
documentServerUrl="http://192.168.0.229/"
config={{
document: {
fileType: "oform",
key: "oform" + Math.random(),
title: "test.oform",
url: "https://d2nlctn12v279m.cloudfront.net/assets/docs/samples/demo.oform"
},
documentType: "word",
}}
height="800px"
events_onDocumentReady={onDocumentReady}
events_onDocumentStateChange={onDocumentStateChange}
events_onChangeContentControl={onChangeContentControl}
/>
</div>
</div>
);
}
export default App;
Here is my current code, and initially, I confirmed that if there were any changes, the events_onChangeContentControl function was functioning. However, one day, this event stopped working.
I don’t think it’s a connection issue with the document server because I have confirmed that events_onDocumentStateChange is still functioning.
Document Server version: 7.3.3.49
Installation method: Docker
OS: ubuntu 22.04.2 LTS
[reference document]
https://api.onlyoffice.com/editors/interactingoutside/fillingform
https://api.onlyoffice.com/editors/react
https://github.com/ONLYOFFICE/document-editor-react code