Refresh View on Form Submit and Record Delete
If there is a view of connected records, Knack does not currently refresh the view of connected records. To work around this, we can implement this custom code so the connected view is also updated as well.
Original Post: https://forums.knack.com/t/refreshing-a-details-view-on-form-submit-record-delete/18301
Some Example Use Cases
Refreshing an Attachments table connected to a parent record form adding or deleting
Refreshing a Invoice Grid Table connected to adding/deleting an invoice line item form
Refreshing a Details View with connected records when a connected record is added or deleted
Keep in mind that for connected records, if you delete the parent record the connected record will no longer show up in the view but will be an orphaned record since Knack does not do cascading deletions.
The JS
Copy/Paste the JS below and replace view_XXX, view_YYY, and view_ZZZ.
view_XXX
is the view used for submitting a form onknack-form-submit.view_XXX
view_YYY
is the view that is being refreshedview_ZZZ
is the view where the record deletion is occurring onknack-record-delete.view_ZZZ
/****************************************/
/*** Refresh View on Submit/Delete ***/
/****************************************/
// A function to refresh a specified view
function refreshView(viewKey) {
Knack.views[viewKey].model.fetch();
setTimeout(() => {
Knack.views[viewKey].render();
Knack.views[viewKey].postRender();
}, 2000);
}
// If record is submitted through form
$(document).on('knack-form-submit.view_XXX', function (event, view, data) {
refreshView('view_YYY');
});
// If record is deleted on the specific view
$(document).on('knack-record-delete.view_ZZZ', function (event, view, data) {
refreshView('view_YYY');
});
Last updated
Was this helpful?