Issue Creating and Updating Text Views through Data Interactive API

CODAP Forums CODAP Help Forum Issue Creating and Updating Text Views through Data Interactive API

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #6475 Score: 1
    Jason Chen
    Participant
    5 pts

    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!

    #6481
    Bill Finzer
    Keymaster

    Hi 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

    #6482
    Jonathan Sandoe
    Keymaster

    Hi 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

    #6483
    Jason Chen
    Participant
    5 pts

    Thanks! 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 to apiText, but in https://github.com/concord-consortium/codap/blob/master/apps/dg/components/text/text_controller.js#L121, the text property is referred to, which console.log says is undefined.

    Jason

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.