- This topic has 3 replies, 3 voices, and was last updated 4 years ago by
Jason Chen.
-
AuthorPosts
-
Hi,
I was trying to create a Text component through the data interactive API. I sent a request like this: https://pastebin.com/mZ2ESUi6. It did create a new text view, but it did not contain any text.
I also tried to update the text view with a request like this: https://pastebin.com/4BbhWY4m. This also leaves the text view empty. If the text view previously had text in it, it would get cleared by the update.
How do I create and update text components through the API? Thanks in advance!
June 7, 2021 at 11:49 pm #6481Bill Finzer
KeymasterHi Jason,
Unfortunately the text API expects an object rather than simply a string. (Probably we should extend it to simply deal nicely with a string, too.)
Here’s an example of a simple (sic) such object:
{ "object": "value", "document": { "children": [ { "type": "paragraph", "children": [ { "text":
This is where selected </span>${<span style="font-style: italic;">pluralize</span>(<span style="color: #000080; font-weight: bold;">this</span>.<span style="color: #660e7a; font-weight: bold;">targetAttributeName</span>)}<span style="color: #008000; font-weight: bold;"> appear.
} ] } ], "objTypes": { "paragraph": "block" } } }You can discern the object format at this Storybook site. I hope that helps.
Bill
June 8, 2021 at 2:05 am #6482Jonathan Sandoe
KeymasterHi Jason,
I investigated a little farther and I found that, weirdly, creating a Text Component doesn’t work for plain text, but update does. For example, the following message:
{ “action”: “update”, “resource”: “component[name]”, “values”: { “text”: “This is some text” } }
I will log a bug about create/textComponent, but you can create, then immediately update as a workaround.
Jonathan
June 8, 2021 at 3:33 pm #6483Thanks! Somehow I’m not able to update with plain text, but updating with the object works so I have a workaround for now. I may have a clue about the creating bug that might be helpful. I noticed that in the API creation code (https://github.com/concord-consortium/codap/blob/master/apps/dg/components/data_interactive/data_interactive_phone_handler.js#L1821-L1823), the
text
property gets remapped toapiText
, but in https://github.com/concord-consortium/codap/blob/master/apps/dg/components/text/text_controller.js#L121, thetext
property is referred to, whichconsole.log
says is undefined.Jason
-
AuthorPosts
- You must be logged in to reply to this topic.