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

Companion settings force reset on value change

 Hi, I'm developing a clockface which requires the user to chose date (a day and a month). Obviously, some months have 30 days others 31, and February having either 28 or 29.

I am able to dynamically create a list of days based on the month selected, so if user selects February, my list of days will go up to 28 ( or 29 depending on year ), but my problem is, when a day and month are selected e.g 31 January, but then the user changes the month such that the day selected is outside of the range of the new month, we'll end up with something like February 31. 

 

I tried additive list as well as a regular select list but couldn't work it out. 

 

My question is, is there a way to force the day to be reset to 1, everytime the month is changed? this needs to be done in the settings/index.js since otherwise we'll get this error:

 

[20:44:50]TypeError: Cannot read property 'name' of undefined
[20:44:50]Uncaught TypeError: Cannot read property 'name' of undefined

 

Any help would be greatly appreciated. Just starting out working with fitbit OS and already very frustrated.

 

Here's what I have:

 

const months = [
{name:"January", value:"1"},
{name:"February", value:"2"},
{name:"March", value:"3"},
{name:"April", value:"4"},
{name:"May", value:"5"},
{name:"June", value:"6"},
{name:"July", value:"7"},
{name:"August", value:"8"},
{name:"September", value:"9"},
{name:"October", value:"10"},
{name:"November", value:"11"},
{name:"December", value:"12"}
];

const days = {
thirtyOne: [
{name:"1", value:"1"},
{name:"2", value:"2"},
{name:"3", value:"3"}
]
// the list above goes until 31, then "thirty" until 30 etc
//
};

function Days(props) { return ( <AdditiveList settingsKey="days" minItems="1" maxItems="1" addAction={ <Select settingsKey="day" label="Select Day" options={days[util.daysInMonth(chosenMonth)]} /> } /> ) } function mySettings(props) { return ( <Page> <Section title={<Text bold align="center">Countdown until:</Text>}> <Months /> <Days /> </Section> </Page> );function Days(props) { return ( <AdditiveList settingsKey="days" minItems="1" maxItems="1" addAction={ <Select settingsKey="day" label="Select Day" options={days[util.daysInMonth(chosenMonth)]} /> } /> ) } function mySettings(props) { return ( <Page> <Section title={<Text bold align="center">Countdown until:</Text>}> <Months /> <Days /> </Section> </Page> ); }

 

Best Answer
0 Votes
0 REPLIES 0