• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Problem using fabrik.form.elements.added

Bauer

Well-Known Member
Whenever I include javascript inside a form_##.js file and include this function
Code:
Fabrik.addEvent('fabrik.form.elements.added', function (block) {
     [js code here]
});
the code only gets run the first time the form is loaded in a session. Or is this by design?

According to the Wiki ( http://fabrikar.com/forums/index.php?wiki/form-javascript-objects/#form-events )...
fabrik.form.elements.added (elements) // All elements have been added to the form's formElements property

To duplicate - create a menu item to a fabrik list. Then in a form_##.js file for that list include this code.
Code:
Fabrik.addEvent('fabrik.form.elements.added', function (block) {
     console.log('start of fabrik.form.elements.added');
     alert('this is js code inside fabrik.form.elements.added');
     console.log('end of fabrik.form.element.added');
});
Click the menu item and edit a row in the list. Save the form then click the menu item (or edit icon in the list) again.

The js code inside the fabrik.form.elements.added (for me anyhow) is only working when the form is first loaded
 
I call this "Phil's Law".
It's working fine for me now too.
Sorry for taking up your time.

But I know I've had it happen to me before too. Go figure.
Just wondering - is your Fabrik.addEvent inside a jQuery(document).ready(function(){ -or- a requirejs(['fab/fabrik'], function () { ???
Mine is now inside a requirejs(['fab/fabrik'], function () {
Isn't that where it should be?
Maybe I had it different before.
 
I always use requirejs(), it's the only reliable way to run code that needs to run after the main Fabrik object is set up. And even though the main Fabrik class doesn't have a lot of code in it, it's deliberately light weight, the DOM is still usually ready before Fabrik is initialized. Remember that jQuery's ready() function is equivalent to Moo's domready event, it fires when the DOM is ready, so when the HTML in the page itself has been processed and the document model created, but before other assets (images, scripts, etc.) are loaded.

And within Fabrik itself, things get a lot more complicated with JS dependencies, as we have an almost infinite number of permutations of what JS gets loaded, and what depends on what to be able to run. So we use the requirejs dependency manager to handle that, whereby everything in Fabrik which uses Javascript registers itself and it's dependencies with requirejs. And the first thing to get loaded is 'fab/fabrik', which then triggers everything that directly depends on that to run (like registering a Fabrik event handler) which in turn trigger anything that rely on those things to run.

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

Thank you.

Members online

Back
Top