1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Save/update form input on change group

Discussion in 'Community' started by eurtnl, Oct 18, 2020.

  1. eurtnl

    eurtnl New Member

    Level: Community
    I have a form whit 10+ groups, is it possible to save/update record when user advance to the next group?
     
  2. troester

    troester Well-Known Member Staff Member

    Level: Community
    You can enable "Save part-edit records" in form/Form processing.
    See tooltip "When changing pages on a multi-page or multi-tab form, save the data entered so far in a temporary table and restore it next time the user returns to the same form / record."
     
  3. eurtnl

    eurtnl New Member

    Level: Community
    I was aware of that feature, but i need the data for a game in progress so i can make a standing during the game.
     
  4. troester

    troester Well-Known Member Staff Member

    Level: Community
  5. eurtnl

    eurtnl New Member

    Level: Community
    Well that helped alot thanks!
    I added the js code to an element (on change / blur), had to add the apply-button to the form first.

    So when a score is entered and i click the next button it updates the record, but the form reloads and goes back to the first group (beginning of the form). How can I can i get the form to advance to the next group instead of the beginning?
     
  6. eurtnl

    eurtnl New Member

    Level: Community
    I'm still trying to solve this.
    What I did is create a file form_11.js and saved it in components/com_fabrik/js
    The content of the file is:
    Code (Javascript):
    Fabrik.addEvent('fabrik.form.page.change', function(form, dir) {
    var form = Fabrik.getBlock('form_11');
    form.doSubmit(new Event.Mock(form._getButton('apply')), form._getButton('apply'));
    });
    But I get an error: Can't find variable: Fabrik
    Anybody got a hint?
     
  7. startpoint

    startpoint Active Member

    Level: Community
    Code (Javascript):
    requirejs(['fab/fabrik'], function() {
    Fabrik.addEvent('fabrik.form.page.change', function(form, dir) {
    var form = Fabrik.getBlock('form_11');
    form.doSubmit(new Event.Mock(form._getButton('apply')), form._getButton('apply'));
    });
    })
     
  8. eurtnl

    eurtnl New Member

    Level: Community
    Thanks! I got rid of the error.
    But the code didn't solve my problem, it even got worse :(

    What I'm trying to achieve is to save/update the record when the user changes from form group (prev/next). The save part is working but after that the form returns to the beginning of the form and not to the next/prev group.
    Second it would be nice to suppress the notification and only show when the user hits the submit button.

    Can this be done?
     
  9. juuser

    juuser Well-Known Member

    Level: Community
    Here's a code I'm using in tabbed templates to return to the same tab after "Apply" is pressed:
    Code (Text):
      document.getElement('button[name=apply]').addEvent('click', function () {
            var active_tab = document.getElements('.nav-tabs > li.active a')[0].id;
            Cookie.write('active_tab_' + Fabrik.getBlock('form').id, active_tab, {duration: 0.1});
        });

        });

        window.addEvent('fabrik.loaded', function() {
        //replace 118 with your form id
        var active_tab = Cookie.read('active_tab_118');
        if (active_tab) {
            jQuery('#'+active_tab).trigger("click");
        }
    Maybe you can adapt this to your need. In multipage-forms, the groups that are not shown, just have "display:none" attribute. So with some jQuery you could probably find out which form child with a class "page" has not "display:none" style applied, loop throught the elements and apply "display:none" again on the pages that were not shown before your "Apply" code was run.
     
  10. eurtnl

    eurtnl New Member

    Level: Community
    Thanks for your reply.
    But with my js knowledge this is out of my league.

    However I'm using "Save part-edited records", maybe I can extract the data from the temp-table.
     

Share This Page