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 AnswerI'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 AnswerThis 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.
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 AnswerTo my experience, once the text is stored in the setting, it will stick. The TextInput will grab it automatically in future.
Best Answer