Hello there, Im a new Yii user and really love it! I've come across some problem I can't seem to be able to solve by myself:
I have in one of my creation form a list of links that can be activated or not (a list of predifened tags). I have used ajaxLinks in combination with a controller action that saves which links have been clicked. It works pretty well except on the visual side, I would like the link class to toggle each time I click on it. My current code is the following:
This will correctly add the class "tagSel" to the link you click on, but it lacks the toggle back (removeClass). I've tried to use the JQuery toggle() function but it doesn't work. Here is the JQuery example for it:
$("p").toggle(function(){
$(this).addClass("selected");
},function(){
$(this).removeClass("selected");
});
How am I supposed to adapt my 'success' function? I've tested several solutions without results… thanks for any help!
not sure what is your spec. if you are trying to hide the link when clicking it and show it on success, you could try to call removeClass() in onclick event.
Actually I got it to work by registering an additional script for each link and without using the success condition. I had already tried your solution Vasiliy but it didn't work as supposed, the links needed TWO clicks to toggle. I guess it is because the registering of the script was issued after the success of the ajax request (click on a link => ajax request => success=registering of the toggle function…=>another click actual function is called).
I had already tried your solution Vasiliy but it didn't work as supposed, the links needed TWO clicks to toggle. I guess it is because the registering of the script was issued after the success of the ajax request (click on a link => ajax request => success=registering of the toggle function...=>another click actual function is called).
Sure, if you tried to register script in ajax response, then it's expected behavior.
Of course, I meant that you should register toggle function before any httprequest - in page body.