Save Listbox Items to Local Storage - Forum

Forum Navigation
You need to log in to create posts and topics.

Save Listbox Items to Local Storage

Hello,

I have a simple list box which users adds items in it at runtime...

how can i save inserted data to local storage?

i tried to save the "Items Variable" which is an array, but when i open app and use "GetData" to read it every letter will be an record in list...

for example i added 1 word like "Phone" to list and when i load it it will be like:

P
h
o
n
e

How can i save and read items of a list using local storage?

Thanks :)

YASIN has reacted to this post.
YASIN

Can you share the code you are using to store and retrieve the values or a sample .neoapp file?
Thanks!

Sure! i wanted to do it but app was in Persian,

i will make a simple English app so it can be useful for other users too.

<?xml version="1.0" encoding="utf-8"?>
<Application>
 <AppTitle>Untitled Application</AppTitle>
 <DesignDeviceName>Desktop</DesignDeviceName>
 <Variables>[list],[myitems],[mylist]</Variables>
 <VariablesScanned>True</VariablesScanned>
 <PageWidth>640</PageWidth>
 <PageHeight>480</PageHeight>
 <AutoSizeWidth>False</AutoSizeWidth>
 <AutoSizeHeight>False</AutoSizeHeight>
 <HideScrollbars>False</HideScrollbars>
 <PublishPlatform>WebApp</PublishPlatform>
 <EmptyBuildFolder>False</EmptyBuildFolder>
 <LanguageCode>en</LanguageCode>
 <MobileOSTypes>[AndroidOS,iOS,WindowsPhoneOS]</MobileOSTypes>
 <WindowState>normal</WindowState>
 <TitleBar>True</TitleBar>
 <Sizeable>True</Sizeable>
 <MaximizeBtn>False</MaximizeBtn>
 <MinimizeBtn>True</MinimizeBtn>
 <SystemMenu>True</SystemMenu>
 <ContextMenu>False</ContextMenu>
 <AlwaysOnTop>False</AlwaysOnTop>
 <ShowInTaskbar>True</ShowInTaskbar>
 <SingleInstance>False</SingleInstance>
 <ChromeKioskMode>False</ChromeKioskMode>
 <Components>
  <FunctionList name="Subroutines"/>
  <LibraryList name="Libraries"/>
  <PageList name="Main">
   <Components>
    <Page id="NewPage">
     <Components>
      <Listbox id="Listbox1">
       <left>63px</left>
       <top>56px</top>
       <width>278px</width>
       <height>357px</height>
       <items>[myitems]</items>
       <variable>[mylist]</variable>
       <multi_select>False</multi_select>
      </Listbox>
      <PushButton id="PushButton1">
       <left>403px</left>
       <top>273px</top>
       <width>157px</width>
       <height>64px</height>
       <caption>Save List</caption>
       <click>SetItem &quot;mylist&quot; [myitems]</click>
      </PushButton>
      <PushButton id="PushButton2">
       <left>404px</left>
       <top>352px</top>
       <width>157px</width>
       <height>64px</height>
       <caption>Load List</caption>
       <click>GetItem &quot;mylist&quot; [myitems]</click>
      </PushButton>
      <PushButton id="PushButton3">
       <left>408px</left>
       <top>52px</top>
       <width>157px</width>
       <height>64px</height>
       <caption>Make Empty Array</caption>
       <click>CreateEmptyArray [myitems]</click>
      </PushButton>
      <PushButton id="PushButton4">
       <left>407px</left>
       <top>137px</top>
       <width>157px</width>
       <height>64px</height>
       <caption>Add Items to List</caption>
       <click>ArrayAddItem [myitems] &quot;random word&quot;
ArrayAddItem [myitems] &quot;hi Luis&quot;
ArrayAddItem [myitems] &quot;VisualNEO Web&quot;
ArrayAddItem [myitems] &quot;what can you do&quot;
ArrayAddItem [myitems] &quot;lets make it fun&quot;
ArrayAddItem [myitems] &quot;what is this record&quot;
ArrayAddItem [myitems] &quot;i add one more&quot;
ArrayAddItem [myitems] &quot;this is last one&quot;</click>
      </PushButton>
     </Components>
    </Page>
   </Components>
  </PageList>
  <PageList name="Master">
   <Components>
    <Page id="MasterPage"/>
   </Components>
  </PageList>
  <PageList name="Dialog">
   <Components>
    <Page id="NewDialog">
     <Components>
      <DialogContainer id="DialogContainer1">
       <left>0px</left>
       <top>0px</top>
       <width>640px</width>
       <height>480px</height>
       <close_button>False</close_button>
      </DialogContainer>
     </Components>
    </Page>
   </Components>
  </PageList>
 </Components>
</Application>

Here is .neoapp file codes.

@noyzen you can't save an array into a LocalStorage variable.
The solution is converting the array content to a JSON string and then save it.
For reading the information back to an array just use ParseJSON.

For saving the data:

StringifyJSON [myitems] [myitems2]
SetItem "mylist" [myitems2]

For loading the data back to an array:

GetItem "mylist" [myitems2]
ParseJSON "[myitems2]" [myitems]

Let me know if it works for you.
Regards.

noyzen and YASIN have reacted to this post.
noyzenYASIN

[SOLVED] Perfect!

thats working now, and exactly like i wanted.

Thanks for help :)

 

Note: Where local data will save and how can i back up them? (Android App)

LocalStorage JavaScript Limitations

Note: Where local data will save and how can i back up them? (Android App)

Although LocalStorage is quite easy to use and useful in many occasions, whenever possible use a server side database to safely store and backup information. The following are limitations and also ways to NOT use localStorage:

  • Do not store sensitive user information in localStorage.
  • It is not a substitute for a server based database as information is only stored on the browser.
  • LocalStorage is limited to 5MB across all major browsers.
  • LocalStorage is quite insecure as it has no form of data protection and can be accessed by any code on your web page.
  • LocalStorage is synchronous. Meaning each operation called would only execute one after the other.

Hope it helps to understand this technology better.

noyzen and smartmedia have reacted to this post.
noyzensmartmedia

Great. Thank you!