Form. Elementin Prototype
Form.Element has several methods in Prototype.js like activate,clear,disable,enable,
etc.But if you want to override those method, how would you do that. Here, I have
tried to do so.
Demonstration
I attempted to override the Form.Element.disable() method in PrototypeJS so that
it adds a custom class to disabled form elements.The way, I tried
Form.Element.disable = function(element) {
element = $(element);
element.blur();
element.disabled = true;
element.addClassName("disabled");
return element;
}
and it works well if I call the method
Form.Element.disable("my_input");
But if I call the method in the samrt way i.e.
$("my_input").disable();
it does not call my method, what it does it calls PrototypeJS built in method. Element.addMethods rescued me.Here it is,
Element.addMethods(["input", "textarea", "select"], {
disable: function(element) {
// stuff here
}
});
Finally what I understand
This is a pretty simple way to override the PrototypeJs method.