mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Adding onNewRecord event for custom widgets
Summary: New onNewRecord event in custom widgets that is triggered when the user selects a blank row. Together with this diff there is PR for grist-help https://github.com/gristlabs/grist-help/pull/150 Test Plan: added test case Reviewers: cyprien Reviewed By: cyprien Differential Revision: https://phab.getgrist.com/D3375
This commit is contained in:
@@ -310,12 +310,24 @@ export function mapColumnNamesBack(data: any, options: {
|
||||
*/
|
||||
export function onRecord(callback: (data: RowRecord | null, mappings: WidgetColumnMap | null) => unknown) {
|
||||
on('message', async function(msg) {
|
||||
if (!msg.tableId || !msg.rowId) { return; }
|
||||
if (!msg.tableId || !msg.rowId || msg.rowId === 'new') { return; }
|
||||
const rec = await docApi.fetchSelectedRecord(msg.rowId);
|
||||
callback(rec, await getMappingsIfChanged(msg));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* For custom widgets, add a handler that will be called whenever the
|
||||
* new (blank) row is selected.
|
||||
*/
|
||||
export function onNewRecord(callback: () => unknown) {
|
||||
on('message', async function(msg) {
|
||||
if (msg.tableId && msg.rowId === 'new') {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* For custom widgets, add a handler that will be called whenever the
|
||||
* selected records change. Handler will be called with a list of records.
|
||||
|
||||
Reference in New Issue
Block a user