JS error in databasejoin.js (onchange js code not run)

robho

New Member
I'm running fabrik 3.1 on joomla 2.5 and am getting a js error in databasejoin-min.js which prevents me from running the js validation code for the element:
> TypeError: e is undefined

This is the problematic code:
Code:
        addNewEventAux: function (action, js) {
                switch (this.options.displayType) {
                case 'dropdown':
                /* falls through */
                default:
                        if (this.element) {
                                this.element.addEvent(action, function (e) {
                                        e.stop();
                                        (typeOf(js) === 'function') ? js.delay(0, this, this) : eval(js);
                                }.bind(this));
                        }
                        break;

e is undefined when trying to run e.stop(). Any ideas? Have you seen this before?

This problem started to happen when I added js validation on the database join element and tried to execute the validation when another element changed value.

Specifically this:
On element X (dropdown element) I run this js code onchange:
$('table___Y').fireEvent('change');

On element Y (database join element) I run this js code onchange:
alert("foo");

Here "alert("foo");" isn't run because of the js error.

(onchange for element Y seems to work well when Y in changed directly. It's only if I manually try to trigger the onchange event that it seems to fail)
 
I'm still seeing this. I'm now on Fabrik 3.3.2 and Joomla 3.4.3.

Can I help debug this? I've tried understanding the js code, but I've not yet understood how it all works.

(If I comment "e.stop()" the code runs the onchange event as expected)
 
I figured this one out. I need to supply an event object to fireEvent(). Like this:
$('object_name').fireEvent('change', {stop: function(){}})
or
$('object_name').fireEvent('change', new Event.Mock);

This could possibly be handled more transparently by fabrik. I've opened a pull request with a possible improvement for consideration: https://github.com/Fabrik/fabrik/pull/1527
 
I'll probably merge that. We're just kind of used to using Event.Mock, which is why it's part of our framework, as there's quite a few little gotchas in addition to e.stop(), where code relies on having the event object.

Before I merge it, can you check it doesn't affect the CDD element? That extends the databasejoin JS class, and I have a feeling there may be some code in there that needs to see the event type (click, change, etc). Probably won't be affcted by this, but needs to be tested.

-- hugh
 
If Event.Mock is the correct way to fix this I'm fine with that and I can drop the pull request. I did see that event objects were used here and there for other elements, but I couldn't easily figure out if and in which context they were used.

I'm not used to JS and don't know mootools so the main problem is probably my lack of knowledge :) Would a section in the wiki make sense to help clarify how to manually trigger events in a correct way?

Should the fireEvent example in this page be updated? http://fabrikar.com/forums/index.php?wiki/element-javascript/
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top