02-17-2018 08:12
02-17-2018 08:12
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.
02-17-2018 10:15 - edited 02-17-2018 12:48
02-17-2018 10:15 - edited 02-17-2018 12:48
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
02-17-2018 10:15 - edited 02-17-2018 12:48
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
07-29-2018 10:20
This should be in the documentation @JonFitbit 🙂
02-28-2022 07:05
02-28-2022 07:05
Liljeberg's answer is wonderful - but one detail could be simplified:
a select just needs something like this:
settingsStorage.setItem("hourmode", '{"selected":[0]}') ;