Alpha Video Training
Results 1 to 3 of 3

Thread: localStorage in UX component. How to intercept it?

  1. #1
    Member ColinJD's Avatar
    Real Name
    Colin Davies
    Join Date
    Jun 2006
    Location
    NZ
    Posts
    489

    Default localStorage in UX component. How to intercept it?

    I have a UX Component with a few text field Controls,
    The UX Properties of 'Persist Variable Values' is checked and works. As the fields persist between usages.
    However when I try to intercept the variables at the event onRestoreVariablesFromLocalStorage
    through using javascript such as .

    Code:
    var surName = localStorage.getItem('SURNAMETEXTBOX');
    
    alert(surName);
    I only get a 'null' result.

    Yes, I have inspected and the variable name is correct.

  2. #2
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,758

    Default Re: localStorage in UX component. How to intercept it?

    You're not understanding how Alpha works with localStorage and Persisting Variables.

    Alpha Persists Variables using a specfic key made up of the word "ALPHA" and the component GUID and the word "._VARIABLES".

    You shouldn't need to go to localStorage because the method .onRestoreVariablesFromLocalStorage() is supposed to have that data in a variable named e.userData.
    However, in typical Alpha fashion... this is a bug... because the data isn't there.

    Instead, the data is in a variable named e.data... but is compounded by another bug (I'm starting to shake my head again). Not all the data is there.

    So, because Alpha is so flakey, you're back to getting the data from localStorage. There's one more problem, though. Alpha uses the componet GUID as part of the localStorage Key. But, Alpha changes the Guid... they remove the dashes from the GUID.

    While in the method .onRestoreVariablesFromLocalStorage(), you can get most of the localStorage Key from this._localStorageSettings.namespace. Then add the word "._VARIABLES" and you can now get the data. Overall, it's a standard Alpha mess... but, as usual, you can work around their bugs and poor programming to get what you need.

    This code builds the localStorage Key and then gets the string data... and parses it into JSON.

    Code:
    var lsKey = this._localStorageSettings.namespace + '._VARIABLES';
    var lsData = JSON.parse(localStorage.getItem(lsKey));
    If you wanted to get the Persisted Variables outside of .onRestoreVariablesFromLocalStorage() you can use {dialog.Object}.

    Code:
    var lsKey = {dialog.Object}._localStorageSettings.namespace + '._VARIABLES';
    var lsData = JSON.parse(localStorage.getItem(lsKey));
    Last edited by Davidk; 11-10-2019 at 11:01 AM.

  3. #3
    Member ColinJD's Avatar
    Real Name
    Colin Davies
    Join Date
    Jun 2006
    Location
    NZ
    Posts
    489

    Default Re: localStorage in UX component. How to intercept it?

    Yes you were correct I was not understanding Alpha with local storage and persistant variables.

    But today was not wasted, as today I learned something. However I'm unsure what it was.

    Code:
    var lsKey = this._localStorageSettings.namespace + '._VARIABLES';
    var lsData = JSON.parse(localStorage.getItem(lsKey));
    var surName = lsData.data.SURNAMETEXTBOX;
    
    alert(surName);
    Now gets me the desired result.
    Many thanks.

Similar Threads

  1. localStorage Limits - can they be increased?
    By Mike Perry in forum Mobile & Browser Applications
    Replies: 3
    Last Post: 08-28-2018, 12:44 PM
  2. use localstorage to populate a textbox lookup
    By browserfiles in forum Mobile & Browser Applications
    Replies: 9
    Last Post: 09-12-2015, 02:55 PM
  3. Localstorage and alphafive version 11
    By GGandhi in forum General Questions
    Replies: 2
    Last Post: 04-02-2015, 01:34 PM
  4. Intercept Alpha Web error message and replace with my own
    By JohnHoff in forum Application Server Version 11 - Web/Browser Applications
    Replies: 0
    Last Post: 05-27-2014, 11:57 AM
  5. Replies: 4
    Last Post: 04-10-2007, 11:54 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •