apostrophecms / apostrophe

A full-featured, open-source content management framework built with Node.js that empowers organizations by combining in-context editing and headless architecture in a full-stack JS environment.
https://apostrophecms.com
MIT License
4.34k stars 590 forks source link

How to programatically insert/update content for a Area field. #4686

Open ezzle opened 1 month ago

ezzle commented 1 month ago

If you're unsure how to proceed with a problem and are not sure if it is a bug, please provide some information so we can help you. You can also use the Apostrophe Discord chat and Github Discussions to ask questions as well.

Question or comment

Please include as much detail as possible so we can help more quickly.

or

.... const area = self.apos.modules['@apostrophecms/rich-text'].newInstance(); const richText = self.apos.modules['@apostrophecms/rich-text'].newInstance(); richText.content = ...<p>${fValue.short_value}</p>...; area.items = [ richText ]; t.documentation.items.push(richText); ....

Details

Version of Node.js: PLEASE NOTE: Only stable LTS versions (10.x and 12.x) are fully supported but we will do our best with newer versions. v22.5.1 Server Operating System: The server (which might be your dev laptop) on which Apostrophe is running. Linux? MacOS X? Windows? Is Docker involved? MacOs Sonoma 14.5

Additional context:

Add any other context about the problem here. If the problem is specific to a browser, OS or mobile device, specify which.

Screenshots If applicable, add screenshots to help explain your problem.

BoDonkey commented 1 month ago

What handler are you using? Something like an afterSave? Is the handler in the same module, or some other module? What is the result when you try the above?

ezzle commented 1 month ago

The context. 1° A specific dedicated piece module to Manage and trigger update and insertion bulk tasks on other piece modules. The handler ”beforeInsert” is in this module. The handler calls dedicated methods in the the same module to insertion or update of other pieces. All update tasks worksfine for primitive or relationship value. I only have issue with area field.

/Users/kiansmacmini/Documents/Documents - Mac mini de

Tshitshi/my-projects/ApoX/apos-esse/modules/frames/update/index.js:227 const area = @.***/rich-text'].newInstance(); ^

TypeError: Cannot read properties of undefined (reading 'newInstance') at Object.updateDocumentation (/Users/kiansmacmini/Documents/Documents

  • Mac mini de Tshitshi/my-projects/ApoX/apos-esse/modules/frames/update/index.js:227:70) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v22.5.1

Le mar. 13 août 2024 à 14:07, Robert Means @.***> a écrit :

What handler are you using? Something like an afterSave? Is the handler in the same module, or some other module? What is the result when you try the above?

— Reply to this email directly, view it on GitHub https://github.com/apostrophecms/apostrophe/issues/4686#issuecomment-2286090401, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALX32WN3MGEGO6R6UGEOLCLZRHZI3AVCNFSM6AAAAABMODDWA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOBWGA4TANBQGE . You are receiving this because you authored the thread.Message ID: @.***>

BoDonkey commented 1 month ago

I'll have to do some testing, I was wondering if it has something to do with the area items needing a unique id, but in looking at your error message - shouldn't it be const area = self.apos.modules['@apostrophecms/rich-text-widget'].newInstance()? Note the module name has the -widget at the end. Although I'm not sure I fully follow the logic.