02-17-2018 08:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

02-17-2018 08:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Is it possible to preselect a value in settings? before the settings write first time in local storage? Thanks
Answered! Go to the Best Answer.
Accepted Solutions
02-17-2018 10:15 - edited 02-17-2018 12:48
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

02-17-2018 10:15 - edited 02-17-2018 12:48
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Yes, but how you do it depends on which type of setting you are setting:
For Selects do a settingsStorage.setItem to the settingsKey of the Select, setting it to one of the values in the options.
So to set 24 hour mode as the default selected value in this Select example...
<Select label={`Clock mode`} settingsKey="hourmode" options={[ {name:"24 hour mode", value:"24h"}, {name:"12 hour mode", value:"12h"} ]} />
... you would need to do:
settingsStorage.setItem("hourmode", JSON.stringify({"selected":[0],"values":[{"name":"24 hour mode","value":"24"}]})) ;
For toggles you just set it to true or false:
settingsStorage.setItem("useweather", JSON.stringify({"value":"true"})) ;
For TextInput and Sliders you just set it like this:
settingsStorage.setItem("theKey", "any text");
or
settingsStorage.setItem("sliderKey", 42;
02-17-2018 10:15 - edited 02-17-2018 12:48
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

02-17-2018 10:15 - edited 02-17-2018 12:48
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Yes, but how you do it depends on which type of setting you are setting:
For Selects do a settingsStorage.setItem to the settingsKey of the Select, setting it to one of the values in the options.
So to set 24 hour mode as the default selected value in this Select example...
<Select label={`Clock mode`} settingsKey="hourmode" options={[ {name:"24 hour mode", value:"24h"}, {name:"12 hour mode", value:"12h"} ]} />
... you would need to do:
settingsStorage.setItem("hourmode", JSON.stringify({"selected":[0],"values":[{"name":"24 hour mode","value":"24"}]})) ;
For toggles you just set it to true or false:
settingsStorage.setItem("useweather", JSON.stringify({"value":"true"})) ;
For TextInput and Sliders you just set it like this:
settingsStorage.setItem("theKey", "any text");
or
settingsStorage.setItem("sliderKey", 42;
07-29-2018 10:20
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

07-29-2018 10:20
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
This should be in the documentation @JonFitbit 🙂
02-28-2022 07:05
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

02-28-2022 07:05
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Liljeberg's answer is wonderful - but one detail could be simplified:
a select just needs something like this:
settingsStorage.setItem("hourmode", '{"selected":[0]}') ;

