Skip to content

Commit b2f0294

Browse files
committed
Added silent option and example
1 parent 8ccf78e commit b2f0294

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

demo/index.html

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<meta name="description" content="Bootstrap Switch Button is a bootstrap plugin that converts checkboxes into responsive switch buttons.">
1616
<meta name="keywords" content="bootstrap, switch, button, bootstrap-checkbox, bootstrap-switch, bootstrap-switch-button, bootstrap-toggle">
1717
<meta name="author" content="https://github.com/gitbrent">
18-
<meta name="version" content="20200215">
18+
<meta name="version" content="20200216">
1919
<meta name="robots" content="index, follow">
2020
<meta name="revisit-after" content="1 month">
2121
<title>Bootstrap Switch Button</title>
@@ -470,6 +470,33 @@ <h3 class="text-secondary mt-4">Event Propagation</h3>
470470
})
471471
</script>
472472
</div>
473+
<h3 class="text-secondary mt-4">Stopping Event Propagation</h3>
474+
<p>
475+
Passing <code>true</code> to the on/off methods will enable the silent option to prevent the control from propagating the change event in
476+
cases where you want to update the controls on/off state, but do not want to fire the onChange event.
477+
</p>
478+
<div class="example">
479+
<input id="toggle-silent" type="checkbox" data-toggle="switchbutton" onchange="$('#chgConsole').text(new Date().toISOString()+' ... change event fired!')">
480+
<button class="btn btn-success" onclick="toggleApiOnSilent()" >On by API (silent)</button>
481+
<button class="btn btn-success" onclick="toggleApiOffSilent()">Off by API (silent)</button>
482+
<button class="btn btn-warning" onclick="toggleApiOnNotSilent()">On by API (not silent)</button>
483+
<button class="btn btn-warning" onclick="toggleApiOffNotSilent()">On by API (not silent)</button>
484+
<script>
485+
function toggleApiOnSilent() {
486+
document.getElementById('toggle-silent').switchButton('on', true);
487+
}
488+
function toggleApiOffSilent() {
489+
document.getElementById('toggle-silent').switchButton('off', true);
490+
}
491+
function toggleApiOnNotSilent() {
492+
document.getElementById('toggle-silent').switchButton('on');
493+
}
494+
function toggleApiOffNotSilent() {
495+
document.getElementById('toggle-silent').switchButton('off');
496+
}
497+
</script>
498+
<pre class="mb-0"><code id="chgConsole" class="text-info"></code></pre>
499+
</div>
473500

474501
<h3 class="text-secondary mt-4">API Input</h3>
475502
<p>This also means that using the API or Input to trigger events will work both ways.</p>

dist/bootstrap-switch-button.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/bootstrap-switch-button.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)