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

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

Open
ezzle opened this issue Aug 13, 2024 · 3 comments
Open

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

ezzle opened this issue Aug 13, 2024 · 3 comments
Labels

Comments

@ezzle
Copy link

ezzle commented Aug 13, 2024

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.

  • What are you trying to do?
    Insert/update content of instance with area field inside an handler method.
    Schema
    fields: { add: { ........ documentation: { // label: 'Documentation', htmlHelp: '<i>Frame documentation, stored under ”:DOCUMENTATION” slot. Distinct from ”description” or ”...description”</i>', type: 'area', options: { widgets: { '@apostrophecms/rich-text': {}, '@apostrophecms/image': {}, '@apostrophecms/video': {}, '@apostrophecms/html': {} } } }, ....

  • What have you already tried?
    inside the handler
    ..... t.documentation.items.push({ metaType: 'widget', type: '@apostrophecms/rich-text', aposPlaceholder: false, content: '<p>fValue.short_value</p>', permalinkIds: [], imageIds: [] }); self.apos.modules[t.type].update(req, t); ....

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); ....

  • Have you already checked the documentation? A3 documentation | A2 documentation
    • Did the docs have a related section but there was not enough information? No related information found.

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.

@ezzle ezzle added the question label Aug 13, 2024
@BoDonkey
Copy link
Contributor

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
Copy link
Author

ezzle commented Aug 13, 2024 via email

@BoDonkey
Copy link
Contributor

BoDonkey commented Aug 13, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants