How to fire js code on event form.submitted only for current form

Status
Not open for further replies.

Makulia

Member
Hello, community.

Any suggestions on how to fire js code on event form.submitted only for current form not for all?
I have several different forms with form_xx.js on this page.
Now page reloads after submitting any form on this page.

My code is inside form_xx.js

Code:
Fabrik.addEvent('fabrik.form.submitted', function(form, event, button){
  setTimeout(function() {
      window.location.href = window.location.href;
      window.location.hash = "ready_for_it";
      location.reload();
  }, 5000);
});

Thanks.
 
How do you recommend implementing this? Removing Fabrik.addEvent('fabrik.form.submitted', function(form, event, button) from every form_xx.js and put it in a single place, then inside o the form id checking? Hm..
I thought that I could add a whole Event for a form with the specific id.

Code:
Fabrik.addEvent('fabrik.form.submitted', function(form, event, button) {
        if (form.id == 55) {
        jQuery('.hit-me > div').empty().prepend(fabrik_success_msg);
        } else if (form.id == 13) {
        console.log ('Done');
        }
    })
 
Last edited:
This is just Javascript programming. It is asynchronous, event driven. Code fired from an event will often need to figure out the context it was called from. The Fabrik form events pass the form object for that purpose, just like "regular" JS events pass the event object, so you can check the target.

-- hugh
 
How to get form.id outside of addEvent? I want to get form.id before I add a new Event.
 
Last edited:
Not sure what you mean. If this code is in a form_X.js file, you know what the id is. It's X.

Hugh


Sent from my Nexus 7 using Tapatalk
 
Yep, sorry. Got it already. Is there a better way to fire js based on form id then my latest example?
 
Nope. That's how to do it if you have more than one form on a page.

Sent from my HTC One using Tapatalk
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top