Struggling with implementing a "select all" checkbox feature as a Junior developer on a complex project utilizing knockout.Js and Typescript. I can't seem to figure out how to select all existing checkboxes.
Here is the HTML:
<td>
<input type="checkbox" data-bind="attr: { value: transactionId }, checked:
$parent.includedTransactions" />
</td>
And here is the ViewModel code snippet:
public includedTransactions = ko.observableArray<number>();
public moveMultipleTransactions = (transactionViewer: TransactionViewer) => {
var cannotMoveTransaction = false;
ko.utils.arrayForEach(this.includedTransactions(), (item) => {
var transaction = ko.utils.arrayFirst(this.transactions(), function (t) {
return item.toString() === t.transactionId.toString();
});
if (transaction.cannotMoveTransaction) {
cannotMoveTransaction = true;
return false;
}
});
if (!cannotMoveTransaction) {
let mmc = new MoveMultipleChargeViewModel(this.id, this.isReservationItem, this.includedTransactions());
if (transactionViewer) {
if (transactionViewer.isReservationItem) {
mmc.toDestination("item");
mmc.reservationItem(transactionViewer.reservationObject);
}
else {
mmc.toDestination("");
mmc.reservation(transactionViewer.reservationObject);
}
}
this.moveMultipleCharges(mmc);
} else {
this.notifier.error("Error", "Once a transaction has been voided, it cannot be moved.");
}
}
I am attempting to create a straightforward "select all" checkbox functionality for all existing checkboxes.
Your support is greatly appreciated.