App Connect State Management Support Product Page

Answered

use local storage data if exist

Asked 12 Feb 2018 15:44:19
1
has this question
12 Feb 2018 15:44:19 Hans Haverlach posted:
Hi,
An input field on a app connect page must show the value of a variable in local storage. I've got that working.
But if the local storage is nog present it must use a default value.
Now I can set the value of this local storage on page load. But the user is able to change the value and save it to that local storage.
So what I want is that on page load the App Connect checks if a value is present in local storage variable and use it, and if not, use a default value.

Can this be done with App Connect?

Replies

Replied 12 Feb 2018 16:51:39
12 Feb 2018 16:51:39 Hans Haverlach replied:
Well, I think I figured it out. On page load I set a default value in a 'default-value' variable in the local storage.
The user might have stored a different value in the 'custom-value' variable.
In the input field I set the value of the input equal to the value of the users custom value variable from the local storage, but use a comparison check, that if value is not there, then use the default value.

I did to know that using the comparison code was allowed in the dmx-bind attr. But it is! Very nice:

<input name="rijenset" type="text" class="" id="rijenset" style="width: 56px; display: inline-block;height: 24px;
margin-top: -9px;" value="" dmx-on:change="local1.set('limitvalue',value,{})" dmx-bind:value="(!local1.data.limitvalue) ? local1.data.default_value:local1.data.limitvalue">


New opportunities!
Replied 12 Feb 2018 18:49:28
12 Feb 2018 18:49:28 Teodor Kuduschiev replied:
Hello Hans,
For the default value you can use the default formatter in app connect data formatter as well, so if no value present, then it will use the default one set:



Your solution is fine also
Replied 18 Jul 2024 07:48:56
18 Jul 2024 07:48:56 Tammy Martin replied:
When considering the use of local storage data in web applications, it's essential to prioritize efficiency and user experience. By utilizing local storage data if it exists, developers can significantly enhance the speed and responsiveness of their applications, as it allows for quicker data retrieval compared to server requests. This approach not only reduces server load but also enables offline access, making the application more robust and user-friendly. For instance, implementing this strategy can be particularly beneficial for logistics companies, where quick access to stored data is crucial for operations. Companies like CGA Logistics could leverage local storage to ensure their tracking and management systems are always up-to-date and accessible, even in areas with poor internet connectivity. For more information about how logistics companies can benefit from such technologies, you can visit their website at CGA Logistics.

Reply to this topic