Jump to content

Disabling Link


shadowayex

Recommended Posts

I was wondering if there were any ways of temporarily disabling a link.What I'm trying to accomplish is that I have a single link that has a click event that is toggled between two functions. The link switches between edit and save, and the saving is done via a JQuery Ajax function. After the user clicks on save I'm wanting to make it so they cannot re-click on edit until the Ajax is completed. I figured I could disable the link first thing in the save function, and re-enable it in the callback function after the Ajax finishes. I'm just unsure on what I can do to disable it without destroying the toggle functionality, which is currently set by a simple JQuery toggle bind.I'm willing to do some redesigning as need be to obtain the functionality I'm looking for.

Link to comment
Share on other sites

couldn't you set an attribute value to check for before running the toggle function like rel="saving".thenif($(this).attr("rel")!="saving"){//run toggle function}when saving has completed change it to $(this).attr("rel")="";
I typically prefer not using attributes for things outside of their purpose. That being said, I don't actually know what the purpose of rel even is, but I have a feeling it's not for this type of thing.On the other hand, it is a simple solution, and if I can't get any other solutions, it might have to do.
Link to comment
Share on other sites

you could apply the same principle to a hidden input on the page, by setting it's value and then checking that instead.

Link to comment
Share on other sites

you could apply the same principle to a hidden input on the page, by setting it's value and then checking that instead.
I do like that solution better.From this I'm taking it that there's no magical disable link functionality built into anything at the moment? I was kind of hoping for something like the input disable attribute :)
Link to comment
Share on other sites

Actually, I hit another problem. When I do that, due to the nature of .toggle(), even though the function is not launched, the event function is still switched. So, the behavior ends up backwards if a user does click save after they already had.

Link to comment
Share on other sites

could you show us the relevant code? Maybe the toggle function could return false or something to keep it from doing anything or inhibiting any sort of default behavior

Link to comment
Share on other sites

$("div.entry-info").find("a:eq(0)").toggle(	function()	{		if ($("#status").val() != "Save")		{			editEntry($(this).parents("div").parents("div").attr("id").substring(5));		}	},	function()	{		saveEntry($(this).parents("div").parents("div").attr("id").substring(5));	});

The #status points to the hidden input who's value is changed in the functions themselves. This is a JQuery bit, so I don't know how to override it's toggling functionality.Pretty much all of this does is swap between launching the editEntry function and saveEntry function. As I said, toggle is something in JQuery.

Link to comment
Share on other sites

$("div.entry-info").find("a:eq(0)").toggle(	function()	{		if ($("#status").val() != "Save")		{			editEntry($(this).parents("div").parents("div").attr("id").substring(5));		}	},	function()	{		saveEntry($(this).parents("div").parents("div").attr("id").substring(5));	});

The #status points to the hidden input who's value is changed in the functions themselves. This is a JQuery bit, so I don't know how to override it's toggling functionality.Pretty much all of this does is swap between launching the editEntry function and saveEntry function. As I said, toggle is something in JQuery.

I don't think there's an issue with the toggle. What does the saveEntry function look like? You should be setting the hidden input's value to 'Save' at the start of that function and then setting it back to 'Edit' when the save operation is complete.
Link to comment
Share on other sites

Well, the editEntry is being blocked like it should, but then the toggle moves on, so even when saveEntry gets done and switches everything back, the toggle had already been switched to save. Does that make sense?So, let's say use clicks edit. The edit function launches and does it's job fine. The toggle function also switches to where saveEntry is set as the click event. The use edits the entry and clicks save. The toggle switches back to edit entry, and the ajax call is made. Before the Ajax returns and the hidden is set, the user could click save again. In this case, the edit function is not launched, due to the if statement, but toggle still switches to Save. When the Ajax returns, the GUI is restored to say Edit and the hidden is set to Edit, but the toggle is set to saveEntry.I hope that is clear.

Link to comment
Share on other sites

That is why you need to check the save status BEFORE running the toggle function, if the toggle function is run first, it will be set to run the alternative option, it remembers which toggle option runs each time. It might be a good idea to run it within a onclick function, so it checks value first before proceeding through the the toggle function. That way toggle switching will remain current to when saving is initiated.

Link to comment
Share on other sites

That is why you need to check the save status BEFORE running the toggle function, if the toggle function is run first, it will be set to run the alternative option, it remembers which toggle option runs each time. It might be a good idea to run it within a onclick function, so it checks value first before proceeding through the the toggle function. That way toggle switching will remain current to when saving is initiated.
The toggle function is a JQuery thing that I cannot change the time of it's calling. As soon as the link it clicked, toggle is launched. The only way I could get around this is by writing my own toggle function, which is looking to be what I may have to do.
Link to comment
Share on other sites

The toggle function is a JQuery thing that I cannot change the time of it's calling. As soon as the link it clicked, toggle is launched. The only way I could get around this is by writing my own toggle function, which is looking to be what I may have to do.
Then you need to wrap the toggle in a new function and assign that new function to the onclick handler instead of toggle.EDIT: Wait, n/m, the toggle is automatically assigned to the click handler...hmm...
Link to comment
Share on other sites

Then you need to wrap the toggle in a new function and assign that new function to the onclick handler instead of toggle.
I'm not sure I can do that. The toggle function is a method for a JQuery object, and it binds to the onclick itself (I think). I don't actually call toggle myself. Ever. I don't even explicitly set toggle to onclick. The code I posted does it all. After that, all I do is click the link. It does all the work for me. In order to do what you're saying, I would have to write my own toggle function.Edit: Haha, you already caught that.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...