Treating a checked box as saved
Checked, assigned and persisted mean different things. Keep the Apply action and saved summary explicit.
Move choices from available to assigned with clear, reversible actions.
Build a reviewer assignment with three distinct states: checked items, the pending assignment and the last saved assignment. Moving a person to the right-hand list is a draft change; Apply is the save.
Use TransferList when comparing available and assigned sets is useful. Use Select for one short choice, TreeSelect for a hierarchy, or a searchable picker for a very large remote directory.
Real BluKavantUI components, with a small application controller. Data and save responses are simulated in this page; reload resets the example.
Loading the interactive recipe…
Displays both sets and moves checked batches.
Apply saves the complete pending set; Discard restores the last accepted set.
Each item has a persistent Key and a human-readable Label. Labels can change or be duplicated; keys identify membership.
A checkbox marks a candidate for Add/Remove. Only a move changes SelectedKeys. Search narrows a list; it is not an assignment command.
SelectionChanged updates pending keys. Apply submits that complete set to the server, which enforces eligibility and required members.
After success, replace saved and pending with the returned keys. After failure, retain pending. Discard uses the last saved keys.
| State / contract | Implementation |
|---|---|
| Items | Complete bounded TransferItem[] with Key, Label, optional Description and IsDisabled. |
| Pending | SelectedKeys: string[]. SelectionChanged returns the new complete set after a move. |
| Required member | Taylor starts selected and IsDisabled=true. The service must also enforce Taylor’s membership. |
| Save result | Return the canonical full key set. Replace the saved baseline only after a successful response. |
Call mount(host, items, savedKeys, saveAssignment). The function keeps saved and pending arrays separate and disables moves during Apply. Implement saveAssignment as an authorized update of the full set. The demo adapter can reject once; no assignments are persisted across reloads.
Install Community and the required Pro add-on for Grid or Kanban recipes, import @blukavantui/community/styles.css, and use a connected host element. The companion CSS styles the surrounding fields, navigation and status messages.
Keep the recipe and shared.ts together; TypeScript resolves the recipe’s ./shared.js import. Add class="recipe-demo" to your host. Supply your records and backend callback as the mount arguments. The downloads use Community 1.0.0 and Pro 1.0.0 imports; the live demo retains its previously verified SDK 0.9.0 runtime.
import { createTransferList } from '@blukavantui/community/transfer-list';
import type {TransferItem} from '@blukavantui/community';
import { node, button, status } from './shared.js';
export type SaveAssignment = (keys: string[]) => Promise<string[]>;
export function mount(host: HTMLElement, items: TransferItem[], initial: string[], save: SaveAssignment) {
let saved = [...initial], pending = [...initial], busy = false, disposed = false;
const summary = node('p'), target = node('div'), actions = node('div', '', 'recipe-toolbar');
host.append(summary, target, actions); const message = status(host);
const transfer = createTransferList(target, {
Items: items, SelectedKeys: pending, ShowSearch: true,
AvailableLabel: 'Available reviewers', SelectedLabel: 'Pending reviewers',
}, { SelectionChanged: keys => { pending = [...keys]; render(); message.textContent = 'Assignment changed locally. Choose Apply to save.'; } });
const apply = button('Apply assignment', async () => {
if (busy) return; busy = true; render(); transfer.update({ IsDisabled: true });
message.textContent = 'Saving assignment…';
try {
const result = await save([...pending]); // Server rechecks eligibility and required members.
if (disposed) return;
saved = [...result]; pending = [...result]; transfer.update({ SelectedKeys: pending });
message.textContent = 'Assignment saved.';
} catch {
if (disposed) return;
message.textContent = 'Could not save. The pending assignment is still here.';
} finally {
if (!disposed) { busy = false; transfer.update({ IsDisabled: false }); render(); }
}
});
const cancel = button('Discard assignment changes', () => {
pending = [...saved]; transfer.update({ SelectedKeys: pending }); render(); message.textContent = 'Restored the last saved assignment.';
});
actions.append(apply, cancel);
function render() {
const names = saved.map(key => items.find(item => item.Key === key)?.Label || key);
summary.textContent = `Saved reviewers: ${names.join(', ') || 'None'}. Pending: ${pending.length}.`;
const unchanged = JSON.stringify([...saved].sort()) === JSON.stringify([...pending].sort());
apply.disabled = busy || unchanged; cancel.disabled = busy || unchanged;
}
render();
return { destroy() { disposed = true; transfer.destroy(); host.replaceChildren(); } };
}
Use BluKavantUi_Community_Inputs → TransferList in either edition. Reference its own BluTransferItem structure; Pro consumers reuse the same Community producer.
| Binding / handler | Implementation |
|---|---|
| Local variables | SavedKeysJson and PendingKeysJson (Text), both initialized from the authorized saved assignment. Add IsSaving (Boolean). |
| Block inputs | Items=your BluTransferItem List; SelectedKeysJson=PendingKeysJson; IsDisabled=IsSaving. Use AvailableLabel and SelectedLabel to name the two sets. |
| OnChanged | Assign its SelectedKeysJson output to PendingKeysJson. This is a local update, not a database write. |
| Apply action | Set IsSaving=True; send PendingKeysJson to your Server Action. On success assign its canonical key JSON to both SavedKeysJson and PendingKeysJson. |
| Failure and discard | On failure keep PendingKeysJson and show an inline error. Always clear IsSaving. Discard assigns SavedKeysJson to PendingKeysJson. |
Add these native Blocks to your consumer Screen, bind the listed events and connect your application actions. The interactive example above runs the web implementation.
Open the full native TransferList API →Checked, assigned and persisted mean different things. Keep the Apply action and saved summary explicit.
Renames and duplicate display names break membership. Persist stable keys.
A disabled required reviewer is an explanation, not enforcement. Recheck the submitted set server-side.
Use the linked component accessibility notes when reviewing focus, keyboard behavior and status announcements in your implementation.