Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Why will my function dothis() work in action but not advanced action?

New Here ,
Aug 20, 2015 Aug 20, 2015

I'm trying to write a function to save text entry box values to local storage.

I wrote my code and saved it in course files, to make it run I need to execute 'makehtmlsave();' on every slide load.

I tried using a listener on 'CPAPI_SLIDEENTER' to execute the code, but somehow this won't work (I thought maybe because my script uses jquery)

I thought I could include the function makehtmlsave(); as part of advanced actions I have running on slide entry, but no luck.

If I create a simple button though just the function makehtmlsave(); this works just fine?

Why would it run in the button simple action but not as part of an advanced action?

477
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 20, 2015 Aug 20, 2015

This is the whole code I a trying to run incase it helps. I am trying to make text entry boxes re-populate with their previous values is a user leaves and comes back.

function makehtmlsave(){

  $("textarea").keyup(function () {

  localStorage[$(this).attr('id')] = $(this).val();

  });

  $("textarea").each(function (i){

  $("#" + this.id).val(localStorage[this.id]);

  });

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 20, 2015 Aug 20, 2015

Just realised it willl work on a button click (the advanced action) so why won't it run on slide entry!? argh!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Aug 21, 2015 Aug 21, 2015

Binding events to Captivate objects is iffy. Also, even if the code worked you would be writing to localStorage after every character typed.

A TEB is made from several elements, for example:

Text_Entry_Box_1

Text_Entry_Box_1c

Text_Entry_Box_1_inputField

Text_Entry_Box_1 (variable name)

To make a TEB repopulate you need to set the TEB to retain value and manipulate the TEB's variable. You could use the TEB's on success to write to the localStorage.

To repopulate the variable I would call the read localStorage function on enter of the first slide and repopulate the TEB's variable.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 22, 2015 Aug 22, 2015

Are you adding your listener to the cpAPIEventEmitter object? Your listener should look something like this:

window.cpAPIEventEmitter.addEventListener("CPAPI_SLIDEENTER",makehtmlsave);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 03, 2016 Feb 03, 2016
LATEST

If you're wanting to just save a TEB's text to local storage, there's a much easier way to do that now.

With the CpExtra widget you can create a Local Storage Variable whose value is automatically stored and recalled from local storage.

You can find more information about CpExtra's local storage variables here: Persisting Data with CpExtra | Infosemantics Pty Ltd‌

You might also want to look into these settings which stop Text Entry Boxes overwriting their linked variable values with their default text: Text Entry Box Behavior | Infosemantics Pty Ltd

Tristan,

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources