10-12-2017 10:31
10-12-2017 10:31
Are there recommendations for how to validate a Text Input field? There seems be a lot of "magic" wrapped up into the settings fields and I'm not certain what hooks are available to change colors or display messages of any sort.
Best Answer01-23-2018 11:18
01-23-2018 11:18
I'm interested to know how anyone has implemented validation.
I would like to limit the user input to 15 characters and if possible validate using a regular expression.
If the input is invalid, how do you let the user know? Can you amend a label in the Settings page?
Best Answer01-23-2018 11:40
Gold Fitbit Product Experts share support knowledge on the forums and advocate for the betterment of Fitbit products and services. Learn more
01-23-2018 11:40
This is a good question. The best way that I've come up with is to include a 'status' element in the settings:
<TextInput
label="Status"
placeholder="Not created."
settingsKey="accountStatus"
disabled="true"
/>You can update the text displayed therein from companion/index.js; eg:
settingsStorage.setItem('accountStatus',{'name':accountStatusMsg});However, I've found that the element doesn't word-wrap, so I have to limit status messages to about 35 characters. The lack of dynamic word-wrapping kinda seems like a bug.
01-23-2018 13:07
01-23-2018 13:07
Thanks @Gondwana
Do you have to load the value the next time the companion loads or does the <TextInput> load the value from settingsStorage itself?
Best Answer01-23-2018 16:16
Gold Fitbit Product Experts share support knowledge on the forums and advocate for the betterment of Fitbit products and services. Learn more
01-23-2018 16:16
To my experience, once the text is stored in the setting, it will stick. The TextInput will grab it automatically in future.
Best Answer