Picture of aaron quinn
how do i reset a component?
by aaron quinn - Friday, 13 January 2017, 7:04 PM
 

i see this code in the text component:

checkIfResetOnRevisit: function() {
var isResetOnRevisit = this.model.get('_isResetOnRevisit');

// If reset is enabled set defaults
if (isResetOnRevisit) {
this.model.reset(isResetOnRevisit);
}
},

is there already a setting somewhere that i turn on/off that resets the component? or is it something i have to implement in the code when building a plugin?

thanks.

Picture of Matt Leathes
Re: how do i reset a component?
by Matt Leathes - Friday, 13 January 2017, 8:20 PM
 

Hi Aaron

Each component has an _isResetOnRevisit property which you can set in the .json for that component - setting this will cause that component to be reset if you leave the page and return to it.

Setting _isResetOnRevisit to "soft" will allow the user to do the component again (this mainly applies to question components as they 'lock' once completed, presentation components - as a rule - do not) but will not require them to do so i.e. for completion purposes they don't have to complete the component again because they've already done so.

Setting it to either "hard" or true will reset but will require the user to complete the component again.

As you can see from the code you posted, all it's doing 'under the hood' is calling componentModel.reset() - so you can write a plugin that calls this directly - we've done the same for a client who wanted a Reset button underneath each main menu item so that the user could have another try at the topic if they wanted to explore that topic again.

If you want to be able to reset components that are currently visible on the page (i.e. without the user have to leave the page and return to it) then I think that is quite a lot trickier to do... this is because the the above is just resetting the component 'model', it doesn't cause the component 'view' to update...

Hope this helps

Picture of aaron quinn
Re: how do i reset a component?
by aaron quinn - Friday, 13 January 2017, 9:38 PM
 

thanks matt, this really helps me a lot.

currently, i'm working on a plugin that has a span which updates its color when clicked, and its targeted object is set to _isVisited = true

clicking the span also completes the component

upon returning to the page the component is complete, remembers that the object isVisited, and that the span has been clicked and is the updated color.

from what i understand, if i add this to the component.json (or a string value of "hard")...

 

"displayTitle": "Component Name",
"title": "Component Name",
"_isResetOnRevisit": true,
"_isAvailable": true,
"_isOptional": false,
"_classes": "",
"_component": "some-component",
"_pageLevelProgress": {
"_isEnabled": true
},

 

...the component needs to be completed again, so the span and it's targeted object should be reset. and if the string value is "soft" the component remains complete, but if i choose, i can reset the colors (or whatever the interactivity may be) and i would do that in the "if":

 

// If reset is enabled set defaults
if (isResetOnRevisit) {
this.model.reset(isResetOnRevisit);
//reset stuff here
}

 

can this "_isResetOnRevisit": true, be a property i include in the component's properties.schema so it can be set with a dropdown?

thanks for your input :)

Picture of Matt Leathes
Re: how do i reset a component?
by Matt Leathes - Tuesday, 24 January 2017, 7:50 PM
 

Hi Aaron

Sorry for the slow response...

As _isResetOnRevisit is listed as one of the Core Model Attributes, I'm a little bit surprised to find it's not already available as a setting in the AT for all components - just like _isOptional and _isAvailable are. I'm not quite sure why that should be... maybe someone else can shed some light on why? It may just be an oversight...

Regardless I don't see any reason why you shouldn't be able to add it to your component's properties.schema - the only caveat being that if it does get added to the core component schema you may have to take it out again.