Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exec function #14

Open
jpbalagolan opened this issue Oct 27, 2014 · 9 comments
Open

Exec function #14

jpbalagolan opened this issue Oct 27, 2014 · 9 comments

Comments

@jpbalagolan
Copy link

I have a website with a sidemenu with a cjax click (Exec) attached that loads a controller (CodeIgniter) which loads a view on the content part. This content has a button with another click(exec) event attached to it like the first one but when i click it, it does not fire the event. In your cjax.class Exec function, you have this comment below:
//some functions return the ajax object?
this is the same part where the issue occurs.

In my point of view, it seems the the later Exec function is not added the the _EventCache according to firebug.

@ajaxboy
Copy link
Owner

ajaxboy commented Oct 27, 2014

Hi Jp,

It appears you are using Exec with an array, that is the only data that will pass through that statement check " && is_array($actions))".

You are correct, this is not being added to cache, and that is what it's suppose to happen in this case. Since you are using an array within Exec, the actions will be tributed to first element that is used in the Exec first parameter, this means when you click the first element it triggers both actions at once!.

Example:
http://cjax.sourceforge.net/examples/bind_actions.php

When you do use an array of action against one element, it will collect all these actions in a single command (that is why you see "unset(CoreEvents::$cache[$v]);" right next to the line you put in question, because it removes that action from the cache, but at that time the action has already amounted/stacked to the first element, as a 'callback' property to the 'AddEventTo' function which is binded to the first element specified in Exec.

$ajax->click('element_id', array(
$ajax->alert('Action 1'),
$ajax->alert('Action 2'),
));
This is what your code is doing ^^^ (sort of speak)

What you need is two click() functions (click() is just an alias for Exec)
$ajax->click('element_id', $ajax->alert('Action 1'));
$ajax->click('element_id2', $ajax->alert('Action 2'));

Let me know if you have any more issues or questions

@ajaxboy
Copy link
Owner

ajaxboy commented Oct 27, 2014

In addition, the comment that you see there, that says '//some functions return the ajax object?', that is in relation to really old versions of Cjax, at some point the $ajax chaining object was returned, but this was practice was stopped, now we return exclusively the 'xmlItem' Object

@jpbalagolan
Copy link
Author

i dont understand really, my scenario is a partial page loading thing. clicking the sidebar to partially load the content in the

part.

@ajaxboy
Copy link
Owner

ajaxboy commented Oct 27, 2014

Could you provide your cjax code so I can further help you?

@jpbalagolan
Copy link
Author

"$ajax->Exec(
'anchor-element-id' , $ajax->Call( 'path/to/controller' , 'div-element-to-replace' )
);"

i added both of them in the main page.php and in the content.php which will be displayed in 'div-element-to-replace' element.

by the way, i had reverted back to jquery for this to work, but your framework is good.

@jpbalagolan
Copy link
Author

i also tried:

  • initializing and calling cjax on the content.php
  • pass $ajax object to controller then to view function in controller
  • put cjax on content.php to main page.php

but nothing worked so far.
hope this helps to improve cjax.

@ajaxboy
Copy link
Owner

ajaxboy commented Oct 28, 2014

Okay, could you post the code you have for both links? I see just one above

@jpbalagolan
Copy link
Author

here it is.

-> for mainpage.php
$ajax->Exec(
'anchor-element-id' , $ajax->Call( 'path/to/controller' , 'div-element-to-replace' )
);

-> for content.php
"$ajax->Exec(
'anchor-element-id' , $ajax->success("Success!")
);"

at some point tried in content.php

$ajax->success("Success!");

it works but not the with the Exec function. the success function should have been a custom dialog form not the success dialog. just use it for testing exec function.

@ajaxboy
Copy link
Owner

ajaxboy commented Oct 28, 2014

There is your issue right there... an element id is unique on the entire page (this is true for any page on the web), having the same id in more than one element will create conflicts. If you just rename one of your elements something else, then it should start working the way it is supposed to.

I guess using the same element id.. has caused cjax to think you are using an array in that element.. hence you ran into the issue that you mentioned above. Notice how in the example I gave you, I included element_id and element_id2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants