Tuesday, August 19, 2008

save_tag to avoid multiple click in IE and Firefox

##############################################################################
# Overrides sumit_tag for disable save after click event --JAGAN REDDY
##############################################################################
def commit_tag(value,options={})
options.stringify_keys!
submit_tag value, options.merge(:onclick => '

if(window.addEventListener)
{
this.disabled = true;
}
else
{ // IE
var element = window.event.srcElement;
var tag = element.tagName.toLowerCase();
if(tag == "input")
{
var click = element.onclick;
var keypress = element.onkeypress;
setTimeout(function() { element.disabled = true; element.onclick = null; element.onkeypress = null; }, 0);
setTimeout(function() { element.disabled = false; element.onclick = click; element.onkeypress =keypress; }, 20000);
}
}
')
end
use this in apllication_helper.rb

No comments: