Faster Edits

Happy New Year to all ….

I appreciate this is a rather niche solution but I thought I’d share with the community. I’m aware that enabling inline editing would overcome the issue of the page refreshing requiring scrolling for long tables, but there are situations where having a popup edit form is required for display rule logic.

Anyway, this is a simple but possibly useful productivity tip :+1:

Efficient Table Edits: A Simple Code Snippet! :rocket:

3 Likes

Very impressive video quality and this is an incredibly useful code snippet! I’d like to offer a few small refinements to improve the maintainability and clarity of the code, which will be really useful especially as the code grows in complexity:

  1. Use Descriptive Variable Names for Views: Assigning a meaningful name to your view identifiers, like ‘view_140’, enhances readability and clarity. This is especially helpful for others (or yourself at a later date) who might work with your code.

  2. Encapsulate Repeated Logic in Functions: To avoid repeating similar code across multiple pages, encapsulate this logic within a function. It’s a clean and efficient practice that simplifies code management and modification.

  3. Document Event Handlers with URLs: It’s a great practice to include comments with the URL of the builder page above each event handler. This makes it much easier to locate and edit the scene. These views can be really hard to find later.

Here’s how these suggestions can be implemented in your code:

// Function to close the modal and update the view
function closeModalAndUpdateView(viewString) {
    // Close the modal
    Knack.closeModal();

    // Fetch/refresh the table associated with the provided view string
    if (Knack.views[viewString]) {
        Knack.views[viewString].model.fetch();
    }
}

// Define a constant for the breeds table view identifier
const breedsTableView = "view_140";

// define another view for the second example
const exampleTableView= "view_321";

// URL to Knack builder page for view_375
$(document).on('knack-form-submit.view_375', function (event, view, record) {
    closeModalAndUpdateView(breedsTableView);
});

// URL to Knack builder page for another view (example: view_123)
$(document).on('knack-form-submit.view_123', function (event, view, record) {
    closeModalAndUpdateView(exampleTableView);
});

The above approach is far more scalable and easier to troubleshoot.

Keep up the fantasic work Carl, I love seeing these videos!

3 Likes

Thank you @Kelson for your positive feedback and kind words. I hold you in high regard and appreciate you taking the time to provide extra code to make the solution more robust and scaleable. :star_struck:

As I’m always keen to point out, I’m not a coder, but I’m a highly accomplished copy and paster :sunglasses:

1 Like

@Normand_Morbern Correct me if I am wrong but as I recall the KTL toolkit does this but can’t remember if it will refresh a parent page with a popup form. What I don’t recall the toolkit doing is automatically closing after submitting and getting a confirmation message. Well done @CarlHolmes and @Kelson

@DeanBozzan62116,

Actually no, the KTL doesn’t do this, but I really like this feature.
I will add it shortly with a new keyword: _cmr for Close Modal and Refresh.

Thanks @Kelson for the snippet.

Norm

3 Likes

Yes and if the keyword could accept multiple views. That would be great. the go to parent page is so slow.

2 Likes

@CSWinnall,

Good idea!

Could be all views by default, no params:
_cmr

Specific views:
_cmr=view_1, view_2, View Title 3...

Norm

1 Like

I was just about to suggest that exactly. Perfect

Hi guys,

It’s done!

This cool feature is now part of the KTL v0.21.1, just released a second ago.

Simply add this keyword to the modal form and upon submit, all parent views will be updated if no parameters are supplied. Otherwise, only the views in parameter will be. Can be view ID or title.

Enjoy,
Norm

2 Likes

Oh yes. I got very frustrated with that.
Changing ubication to all the way up after editing is not normal.
I think this function should be a default in Knack.

I would go much further than just after in-line editing.
I would implement it also after leaving a child page, meaning also in the correct menu Tab.

Just imagine if each time we edit a cell in Google Sheet we would have to go all the way up. Not intuitive neither modern behavior.

Please Knack Team. :pray:

2 Likes

Meanwhile I would highly appreciate the same code functionality for going back to the same click link/button/field from a child page, or any page actually.

and even better for the whole App, not only some precise page/pages.

tks!

Amazing @CarlHolmes and all. Love to see all of the collaboration :handshake:
I can’t think of a reason this should not be default behavior?

4 Likes

@Kara I agree!

1 Like

Agreed, I’ve replied to your Slack message with a more detailed response :+1: