Table/Form Refresh

I built an invoice using the Knack recipe and it works almost flawlessly, however, when I add a line item, the Asset column(s) doesn’t refresh. As you can see the Quantity (3) updates and the extended price ($90.00) updates, but the asset description does not. I must refresh the browser page for Asset columns to display. As a test, I added both the a Text Formula Field, as well as the root field. This isn’t device specific, as I’ve tried on desktop & a tablet with the same result. I really don’t want the answer to be to refresh the browser page every time an item is added. Thank you in advance for your expertise and advice!!

Hi @JarrodSevi20608 - This is one of the issues with having a form that adds a record embedded in the page rather than linking from a menu.

You have a few options.

1 - Refresh the page after each item added, not a great option and not one I’d recommend.
2 - Add the form again and check the box to link it from a menu. Set the form as a modal popup and change the form submit to redirect to parent. This will reload the parent page on submission and pull through the connected values.
3 - Add the below JavaScript so when you submit the form it reloads (fetches) the table.

$(document).on(‘knack-form-submit.view_xxx’, function(event, view, record) {
Knack.views[“view_xxx”].model.fetch();
});

3 Likes

@CarlHolmes Thank You! I opted for #2 for now. I greatly appreciate your advice!

1 Like

How do I find the view number? [“view_xxx”]

@Chris9 - From the Pages section of the builder, navigate to the page and click on the specific form component. The view number will be displayed in the URL address bar in your browser.

YES!!! Thank you @CarlHolmes !!!
I have always used option 2, but wondering how hard it would be to make a JS refresh option! (Still learning)
I am implementing this in one of my apps right now!
If I could press the heart 5 times I would!!!
:+1:

1 Like

Is there a way to add multiple view numbers to Knack.views[“view_xxx”]?
Or would you have to run this code snippet for each view you want to update?

In my instance, I would like to update three of six tables present on the page and not update the other tables (or the pivot tables that are on the page as well.)

Seems doing it this way works for multiple views…

$(document).on('knack-form-submit.view_1589', function(event, view, record) {
   Knack.views["view_1578"].model.fetch();
   Knack.views["view_1580"].model.fetch();
   Knack.views["view_1582"].model.fetch();
});
1 Like

That’s how I do it :+1:

1 Like

Hi guys,

I saw your post and it gave me the idea to integrate it to the KTL.
I’ve just completed the release, and it works beautifully.

All you have to do is go in the Builder and add this flag to your Form’s title:
REFRESH_VIEW=Purchases,Client Sales

In this example, I have two parameters separated by commas that are the exact text or my tables to be updated in that scene. You can have as many as you need.

The code looks like this:

on view render any:
if (view.title.includes('REFRESH_VIEW'))
    ktl.views.addSubmitToViewRefresh(view);

--------

addSubmitToViewRefresh(view) {
    if (!view.title) return;
    var views = view.title.split('REFRESH_VIEW=');
    if (views.length !== 2) return;
    views = views[1].split(',');
    var foundViewIds = [];
    for (var i = 0; i < views.length; i++) {
        var viewTitle = views[i].trim();
        console.log('viewTitle =', viewTitle);
        var viewId = ktl.scenes.findViewWithTitle(viewTitle, true, view.key);
        if (viewId) {
            foundViewIds.push(viewId);
        }
    }

    if (foundViewIds.length) {
        $(document).on('knack-form-submit.' + view.key, () => {
            ktl.views.refreshViewArray(foundViewIds)
        })
    }
}

In the Builder:

You can learn how it’s made and see all the details in this file: KTL.js

Hope you like it, keep me informed!

Cheers,
Normand

2 Likes

Fantastic. Can’t wait till a get a minute to play around with this…

Thanks Erik!

Just wait an hour or two, I’m doing some major simplification of the install process. The documentation is currently out of sync and I’m updating it now.

Will let you know asap.

Normand

1 Like

Erik,

You may go see now, all is updated.
Let me know what you like and don’t like. What you’d like to see added, changed or upgraded.

Cheers,
Norm

1 Like

I’m in the documentation now.
Very cool.
Thanks for sharing.
I’ll give feedback as I’m able.

1 Like

Nice Code!! Thank you. This helps alot!