Lieutenant Dan
Lieutenant Dan

Reputation: 8274

Adding function to Bootstrap Switch State

Form Field:

<div class="form-group">In-Store Exclusive.
<div class="make-switch pull-right">
<input type="checkbox" id="radstuff" <%if (offer.get('inStoreOnly')) {%>checked<%}%>  disabled>
</div>
</div>

Which outputs as:

enter image description here

I am really trying to do something after the 'On or Off' state is toggled. Default is OFF, OK; but I want to hit 'ON' and do something. Say trigger a link opening. I cannot figure out how to access this.

coolfunction: function() {
            if offer.get('#radstuff').is('.switch-on');
        {
             window.open("http://www.facebook.com/sharer.php?s=100&p[title]=YOUR_TITLE&p[summary]=YOUR_SUMMARY&p[url]=YOUR_URL&p[images[0]=YOUR_IMAGE_TO_SHARE_OBJECT.com",'_blank');
        },

Update: Most Recent Attempt.

    coolfunction: function ()
      offer.get('#radstuff').parent().is('.switch-on') {
   /*   return true;  */
       alert('Test');
    },

After clicking 'OFF' as the above output referenced; NADA.

Upvotes: 0

Views: 967

Answers (1)

Gregg
Gregg

Reputation: 35864

Assuming you're using this widget, you're not accessing the correct markup to find .switch-on.

The markup that is created looks kind of like:

<div class='make-switch has-switch' >
   <div class='switch-on switch-animate'>
     <input type='checkbox' checked />
     ....
   </div>
</div>

You're code is expecting the input[checkbox] element to get the .switch-on / .switch-off classes, but it is a div one level higher. So maybe something like:

offer.get('#radstuff').parent().is('.switch-on')

Upvotes: 1

Related Questions