Toggle create default state

Hi
how can i set the default state of a toggle in create?

var toggle = app.toggle.create({
  el: '.toggle',
  on: {
    change: function () {
      console.log('Toggle changed')
    }
  }
})

this works but now i cant change the state of the toggle without the event firing
in my app im changing records and each record have a value for the toggle already.
so i need to change the toggle between records with no event. and with event if the user change it from the UI

It depends on toggle input state. Set input checked prop before creating a toggle:

// set it initially checked
$('.toggle input').prop('checked', true);

var toggle = app.toggle.create({
  el: '.toggle',
  on: {
    change: function () {
      console.log('Toggle changed')
    }
  }
})

but i need to set the value every time the user go to the page.
i solved it by setting a Boolean and ignore the change event if the page is loading

1 Like