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
This reply was removed on 7/22/2024 11:11:43 AM.
See the changelog

Reply to this topic