Is there an easy solution for persisting input values? #887
-
Currently if I switch to a different "page" within the framework, all my inputs are reset to their default values. Is there a way to persist those values while the session is live - and possibly across sessions (e.g. using localStorage or a database connection)? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes I think you could use localStorage to save state (or sessionStorage if you want two browser windows to have their own separate history, which I tend to prefer); then set the initial value of fresh Inputs to the stored value, if any. It could go like this (in two different js code blocks): ```js
const defaultColor = "#ff0000";
const color = view(Inputs.color({value: sessionStorage.getItem("color") ?? defaultColor}));
```
```js
{
sessionStorage.setItem("color", color);
}
``` |
Beta Was this translation helpful? Give feedback.
Yes I think you could use localStorage to save state (or sessionStorage if you want two browser windows to have their own separate history, which I tend to prefer); then set the initial value of fresh Inputs to the stored value, if any.
It could go like this (in two different js code blocks):