Forums

Function inside Events not working properly on 6.0.7

flashfs 28 Aug, 2017
I created a JS action with a simple function
function testFunc() { alert('teste'); }

And then I created a simple radiobox. On Events tab I selected On Change, Value empty, Action Function, and Element identifier testFunc. I was expecting that the function would be called when I select any option on radiobox, but nothing is happening. So, how do you call a JS function from Events tab?
flashfs 29 Aug, 2017
Well, trying to debug the application, I've found that this line is not working properly:
jQuery.each(event['identifier'], function(idi, ident){
						if(ident.substring(0, 1) == '#' || ident.substring(0, 1) == '.' || ident.substring(0, 1) == '['){
							event_targets = jQuery.merge(event_targets, jQuery(ident));
						}else{
							event_targets = jQuery.merge(event_targets, jQuery(':input[name="' + ident + '"]'));
						}
					});

If i write a function name on Events tab, it will go to the else, so a wrong behavior. I tried to write [testFunc] so it goes to the first if. It indeed enters on the first if and outputs the correct ident, but outputting jQuery(ident) returns nothing. Does it have something to do with the ordering of js code? I can see that cegcore2 library is being loaded before the testFunc code. Maybe when it tries to access the testFunc it still doesn't exist.

[edit] Hmm.. I can see that it is not related to the ordering, because if call my function inside that code, it does work. So, I can't understand why jQuery(ident) is returning nothing. Maybe because I'm trying to use the function name on Events tab in the wrong way.

[edit2] If I don't have an event_targets, the code will never get to the line
if(jQuery.inArray('function', event.action) > -1){
								jQuery.each(event['identifier'], function(idi, ident){
									if($eve.type != 'ready' && window[ident] != undefined){
										window[ident](jQuery(inp));
									}
								});
							}
Max_admin 31 Aug, 2017
Answer
Hi flashfs,

Bug found and fixed, a new update should be ready soon!

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
seppo 09 Nov, 2018
Have this bug re-appeared?
I had similar problem, which I posted here
https://www.chronoengine.com/forums/posts/t106332/how-to-use-elements-event-tab

Shortly:
I have a function in Javascript element at Designt tab. I also tested same with having javascript function at Setup-tab with (both are seen when seeing pager source so there shouldn't be any problem/difference in that). In the function all I have is normal alert, like flashfs had here.
I have a button, where on the Events tab I selected Function (as click-event), and the name of function as identifier. Didn't work. I tried both with ( ) and without them.
So that seems like this bug mentioned here, appearing again.
As related to this, is it possible to add an argument to function call here? This would of course require use of parenthesis in the call.


The version of Chronoforms is 6.0.20, while Joomla is of version 3.9.0.
This topic is locked and no more replies can be posted.