Picture of Henrik Aabom
Updating comp item texts
by Henrik Aabom - Tuesday, 20 October 2020, 9:15 AM
 

Hi all

In older versions of Adapt (framework v.2-4-0, AT v.0-8-0), it was possible to do this:

adapt.findById('5f8955a59dc1ee04ac98a044').attributes._items[0].body = '<p>New body text</p>';

to change the item body text inside an Accordion, and when the user navigated to the page with the Accordion, the component was rendered with the updated body text.

But this doesn't work in Framework version 5.7.0 (AT v. 0.10.4). The components model is updated, but it is not rendered with the new text.

However, it works fine to update the Display Title like this:

adapt.findById('5f8955a59dc1ee04ac98a044').attributes.displayTitle = 'New Display Title';

Should I be doing something special to update the Accordion's item body text in the new version of Adapt?

Thanks alot

Picture of Matt Leathes
Re: Updating comp item texts
by Matt Leathes - Tuesday, 20 October 2020, 11:39 AM
 

Hi Henrik

I think it was around 2018 we updated components like Accordion to use a new, shared, data model - ItemsComponentModel (added in FW v3.2.0).

You can still do this, you just have to work with the new data model instead:

Adapt.findById('c-45').getItem(0).set({ title: 'Hello Henrik', body: 'this is how you change the first item of an accordion in Adapt these days. Hope this helps...'});
Picture of Henrik Aabom
Re: Updating comp item texts
by Henrik Aabom - Wednesday, 21 October 2020, 9:05 AM
 

Thank you so much Matt

Haha, yeah, we are way behind, I know. We are in the process of upgrading our Adapt-solutions, which is actually why I ran into the problem. So hopefully we will be on the newest version soon! Fingers crossed :)

It works with this:

Adapt.findById('5f8955a59dc1ee04ac98a044').getItem(0).set({ title: 'Hello Henrik', body: 'this is how you change the first item of an accordion in Adapt these days. Hope this helps...'});

But I couldn't get it to work by using Adapt.findById('c39'), which is the cid in the Accordion's model, or Adapt.findById('c-39') for that matter. Where do I find the correct c-id to use?

Picture of Matt Leathes
Re: Updating comp item texts
by Matt Leathes - Wednesday, 21 October 2020, 11:39 AM
 
But I couldn't get it to work by using Adapt.findById('c39'), which is the cid in the Accordion's model, or Adapt.findById('c-39') for that matter. Where do I find the correct c-id to use?

You don't use the cid property at all. That's an internal Backbone thing. My use of a framework-style component id may have confused matters. The authoring tool automatically generates component ids like '5f8955a59dc1ee04ac98a044' but when developing in the Framework you have to set them up manually and they typically get prefixed with 'co-', 'a-', 'b-' or 'c-' to represent content object, article, block & component.

In the example I used above, c-45 is the component ID of the accordion in the v5 demo course: https://adaptlearning.github.io/v5demo/#/id/c-45

Picture of Henrik Aabom
Re: Updating comp item texts
by Henrik Aabom - Wednesday, 21 October 2020, 12:14 PM
 

Ah of course! I should have seen that... Thanks again for the reply, then everything works perfectly :)