Skip to content

Commit 5d9ae89

Browse files
committed
Added new section on silent mode
1 parent ddcae87 commit 5d9ae89

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Project
3535
- [Methods](#methods)
3636
- [Events](#events)
3737
- [Event Propagation](#event-propagation)
38+
- [Stopping Event Propagation](#stopping-event-propagation)
3839
- [API vs Input](#api-vs-input)
3940

4041
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -150,6 +151,32 @@ You should listen to events from the `<input type="checkbox">` directly rather t
150151
</script>
151152
```
152153

154+
## Stopping Event Propagation
155+
Passing `true` to the on/off methods will enable the silent option to prevent the control from propagating the change event in
156+
cases where you want to update the controls on/off state, but do not want to fire the onChange event.
157+
158+
```html
159+
<input id="toggle-silent" type="checkbox" data-toggle="toggle">
160+
<button class="btn btn-success" onclick="toggleApiOnSilent()" >On by API (silent)</button>
161+
<button class="btn btn-success" onclick="toggleApiOffSilent()">Off by API (silent)</button>
162+
<button class="btn btn-warning" onclick="toggleApiOnNotSilent()">On by API (not silent)</button>
163+
<button class="btn btn-warning" onclick="toggleApiOffNotSilent()">On by API (not silent)</button>
164+
<script>
165+
function toggleApiOnSilent() {
166+
$('#toggle-silent').bootstrapToggle('on', true);
167+
}
168+
function toggleApiOffSilent() {
169+
$('#toggle-silent').bootstrapToggle('off', true);
170+
}
171+
function toggleApiOnNotSilent() {
172+
$('#toggle-silent').bootstrapToggle('on');
173+
}
174+
function toggleApiOffNotSilent() {
175+
$('#toggle-silent').bootstrapToggle('off');
176+
}
177+
</script>
178+
```
179+
153180
## API vs Input
154181
This also means that using the API or Input to trigger events will work both ways.
155182

0 commit comments

Comments
 (0)