locked
How to set a default value in a preferences panel (toggleswitch)

    Question

  • I want to set the state of a ToggleSwitch in the ready event of my preferences.html page.  I can't figure out how to do that.  I can get the change of state which seems to come back in the "which" property, but I can't see to set it when it comes up. 

    Thoughts?

        <div id="ToggleWhitelist" data-win-control="WinJS.UI.ToggleSwitch" data-win-options="{labelOn: 'White List Only' ,labelOff: 'All Senders', title: 'Only Include White Listed Senders' }"></div>


     ready: function (element, options) {
                
                Windows.ApplicationModel.Search.SearchPane.getForCurrentView().showOnKeyboardInput = false;
                
                var toggle = document.getElementById("ToggleWhitelist");
                
                if (AE.Constants.ShowWhiteListOnly == true) {
                    toggle.checked = false;
                } else {
                    toggle.checked = true;
                }

    working below so I think that means I'm getting the right ID:

    document.getElementById("ToggleWhitelist").addEventListener("click",
                    function (v) {
                        if (v.which == 1) {
                            AE.Constants.ShowWhiteListOnly = true;
                        } else {
                            AE.Constants.ShowWhiteListOnly = false;
                        }
                      
                        
                        AE.Functions.fetchEmail(WinJS.Navigation, AE.Constants.Utils.emailSearchString, function () {
                            //var x = document.getElementById('progresscontrolid');
                            //x.style.visibility = "hidden";
                        });
    
                    }, false);


    Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider

    Tuesday, September 25, 2012 4:16 AM

Answers

  • Try this:

     var toggle = document.getElementById("ToggleWhitelist").winControl;

    You need to reference the winControl property for any WinJS UI controls.

    Rob

    Tuesday, September 25, 2012 5:06 AM