I am quite new to knockoutjs and I am trying to create two toggles. When toggle one is switched off and then toggle two is switched off by the user, toggle one should be switched on and vice versa.
function alternatetogglesWithOrWithoutCreditRequests() {
if (!viewModel.withPendingCreditRequests()) {
viewModel.withoutPendingCreditRequests(true)
}
else if (!viewModel.withoutPendingCreditRequests()) {
viewModel.withPendingCreditRequests(true)
}
}
This code above does not work all the time because in both cases the withPendingCreditRequests
and the withoutPendingCredit
observables are false.
Below is the html for the toggles:
<div>
<toggle-switch params="enable: invoiceFiltersActive, checked: withPendingCreditRequests, label: 'With Pending Credit Requests'">
</toggle-switch>
</div>
<div>
<toggle-switch params="enable: invoiceFiltersActive, checked: withoutPendingCreditRequests, label: 'Without Pending Credit Requests'">
</toggle-switch>
</div>