JavaScript event when clicking Next on multi-page forms

softforge

Member
I have tried very hard to get my own JS code running when the next button is clicked but so far I have failed.

Based on this page:

http://fabrikar.com/forums/index.php?wiki/form-javascript/

I have created a file called form_X.js with the following code:
Code:
Fabrik.addEvent('fabrik.form.doelementfx', function(form){
    alert('Event - fabrik.form.doelementfx');
});
 
Fabrik.addEvent('fabrik.form.elements.added', function(elements){
    alert('Event - fabrik.form.elements.added');
});
 
Fabrik.addEvent('fabrik.form.groups.save', function(form){
    alert('Event - fabrik.form.groups.save');
});
 
Fabrik.addEvent('fabrik.form.groups.save.start', function(form){
    alert('Event - fabrik.form.groups.save.start');   
});
 
Fabrik.addEvent('fabrik.form.groups.save.end', function(form, json){
    alert('Event - fabrik.form.groups.save.end');   
});
 
Fabrik.addEvent('fabrik.form.group.delete', function(form, event){
    alert('Event - fabrik.form.group.delete');   
});
 
Fabrik.addEvent('fabrik.form.group.delete.end', function(form, event, groupId, repeatCounter){
    alert('Event - fabrik.form.group.delete.end');   
});
 
Fabrik.addEvent('fabrik.form.group.duplicate', function(form, event){
    alert('Event - fabrik.form.group.duplicate');   
});
 
Fabrik.addEvent('fabrik.form.group.duplicate.end', function(form, event, groupId, repeatCounter){
    alert('Event - fabrik.form.group.duplicate.end');   
});
 
Fabrik.addEvent('fabrik.form.submit.start', function(form, event, button){
    alert('Event (with form submission prevention) - fabrik.form.submit.start');
    form.result = false;   
});
 
Fabrik.addEvent('fabrik.form.submitted', function(form){
    alert('Event - fabrik.form.submitted');   
});
 
Fabrik.addEvent('fabrik.form.update', function(form, json){
    alert('Event - fabrik.form.update');   
});
 
Fabrik.addEvent('fabrik.form.reset', function(form){
    alert('Event - fabrik.form.reset');   
});

I get no JavaScript errors and fabrik.form.elements.added gets triggered when the page loads and fabrik.form.submit.start gets triggered when the form is submitted but none of them get triggered when the next page is triggered.

What I need is an event that gets triggered if the Next button is clicked and all the validations pass (ie, if the next page is actually shown). According to this page, it looks possible in Fabrik v2 with the event onCompleteElementValidation but I think it has got gone missing in v3 when converted to the new system:

http://fabrikar.com/wiki/index.php/Form_plguin_javascript

I sort of expected fabrik.form.submitted to do this as it is called when the form is submitted with AJAX (which is effectively what happens on each page). However it is only partially submitted for validation so maybe there needs to be a new event something like fabrik.form.submit.validate [form, json] which is called after a (successful?) validation occurs so would be called per page (or per element if AJAX validation was set to yes). As long as it was possible to tell which page (or element) was validated successfully (or otherwise) this would be perfect for me and I think very flexible or other needs.

Let me know if I'm missing something or if this could be easily implemented. Whether this is possible or not is a fundamental point on how we design this system.

Thanks for considering! :D
 
Can you post the url to the form please? Its always very hard to comment on JS without seeing the actual page.

I sort of expected fabrik.form.submitted to do this as it is called when the form is submitted with AJAX (which is effectively what happens on each page).
You're expecting something then that doesn't happen. Moving between pages is not submitting the form, as nothing is saved to the form's list when you move between pages.

If you update from github you can use the 'fabrik.form.page.chage.end' event, does that achieve what you are after?
 
Thanks Rob, that is exactly the event I needed. :)

Out of interest, is meant to be 'fabrik.form.page.chage.end' or 'fabrik.form.page.change.end'? I searched through all the code and they both appear.

Thanks again!
 
Hmmmm. Looks like Rob had one of his spelling farts. At the moment we seem to fire both, but obviously the right one to use is change. I'll check with Rob before I kill off the other one, and correct the place it gets used (in the google map element).

-- hugh
 
best not to kill off the other one, as there may be existing sites using it.
 
I suspect if they had the choice between the two, they'd choose the one spelled correctly. :)

But I'll leave it be.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top