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

Toggle settings getting ReferenceError: toggle is not defined

I am trying to implement a toggle in my settings but I keep getting a reference error for not being defined and I have no idea why:

 

in index.jsx:

function mySettings(props) {
  return (
    <Page>  
<Section>
      <Toggle
          settingsKey="toggle"
          label="Manually Set High & Low Threshold?"
        />
      
        <TextInput
          label="High threshold"
          settingsKey="highThresholdIn"
          disabled={!(props.settings.toggle === "true")}
        />
        <TextInput
        label="Low threshold"
        settingsKey="lowThresholdIn"
          disabled={!(props.settings.toggle === "true")}
        />
      </Section>
 </Page>  
  );
}

registerSettingsPage(mySettings);

and in index.js:

import * as messaging from "messaging";
import { encode } from 'cbor';
import { settingsStorage } from "settings";
import { me } from "companion";
...
if(settingsStorage.getItem( 'toggle' )) { manualHighLow = JSON.parse(settingsStorage.getItem( 'toggle' )); console.log("manual high low: " + manualHighLow) } else { manualHighLow = false; }

The error Im getting is:

ReferenceError: toggle is not defined
    settings.settingsStorage.onchange at companion/index.js:336,30
    t.e.dispatchEventToListener at companion-runtime:/bootstrap.js:16,3910
    t.e.dispatchEvent at companion-runtime:/bootstrap.js:16,3427
    ? at undefined:1,37
    EventEmitter.electron.ipcRenderer.on at C:\Users\xylotek\AppData\Local\Programs\@fitbitsimulator\resources\electron.asar\renderer\init.js:63,28
    emitMany at events.js:146,13
    EventEmitter.emit at events.js:223,7

Any ideas?

 

Thanks!

Best Answer
0 Votes
2 REPLIES 2

What does the onchange event look like in your companion/index.js?

 

settings.settingsStorage.onchange at companion/index.js:336,30

 

Best Answer
0 Votes

Hi Jon,

 

Thanks for the reply. I've since played around with it and got it to work. I cant recall what the onchange looked like at the time but playing around with the name of the key to something else seemed to work for whatever reason.

Best Answer
0 Votes