Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Preselect a value in settings

ANSWERED

Is it possible to preselect a value in settings? before the settings write first time in local storage? Thanks

Fitbit Ionic, Nokia 7 plus
Best Answer
1 BEST ANSWER

Accepted Solutions

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;

 

View best answer in original post

Best Answer
3 REPLIES 3

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;

 

Best Answer

This should be in the documentation @JonFitbit 🙂

Best Answer

Liljeberg's answer is wonderful - but one detail could be simplified:

 

a select just needs something like this:

settingsStorage.setItem("hourmode", '{"selected":[0]}') ;
Best Answer
0 Votes