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

JSX assign default values in Settings [text input]

ANSWERED

What is the best way to populate values on the Settings page, if not input manually?

 

It works fine for the user entering data on the settings page, which gets sent to the companion, and then to the app, but the reverse doesn't seem to work at all.

 

EG.

In the JSX

 

<TextInput
label="Enter the place"
settingsKey="place"
defaultValue="Paris"
/>

 

In the companion [hard coded] as first line

settingsStorage.setItem("place", "Madrid");

 

When the Settings page appears "place" has no value. Neither Paris nor Madrid.

 

 

Author | ch, passion for improvement.

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

In your setItem, that's probably not the correct format for the value that <TextInput> uses.

Use console.log to find out what a <TextInput> stores in settingsStorage, then craft your setItem to match it.

A possible gotcha is that setItem only takes string values.

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
0 Votes
4 REPLIES 4

In your setItem, that's probably not the correct format for the value that <TextInput> uses.

Use console.log to find out what a <TextInput> stores in settingsStorage, then craft your setItem to match it.

A possible gotcha is that setItem only takes string values.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

@Gondwana- thanks! that was it, well spotted!

 

correct coding is:

settingsStorage.setItem("place", '{"name":"Madrid"}');

Author | ch, passion for improvement.

Best Answer

@Guy_  No worries. I'm glad you didn't take issue with me giving you more homework instead of just serving up the answer (which I didn't know off the top of my head).

I learnt something too. I always use JSON.stringify when putting objects into settings, but your solution is nicer.

Peter McLennan
Gondwana Software
Best Answer

@Gondwana  - thanks, should have thought of stringify too! Hard coding avoids unknowns.

Author | ch, passion for improvement.

Best Answer