PDA

View Full Version : [CLOSED] Set default listeners, properties for all textboxes in application



jchau
Oct 08, 2008, 10:54 AM
I have an application requirement where all textfields must have property X set to 'Blah' and must have a listener on the change event to execute some 'Y' javascript. There can be multiple developers working on the same project, and I want to ensure that property and that listener are always set correctly. I thought of creating a custom class that inherits from Coolite's TextField and default the property and listener. That isn't ideal because someone may choose to still use Coolite's TextField instead of the custom one. Is there a way to do this in javascript by overriding the Ext TextField class? I been looking up Ext.override but that seems to override functionality of an existing method. Ext.Extend sounds promising but that creates a new class in javascript and I will have to create another new server class too.

geoffrey.mcgill
Oct 08, 2008, 11:06 AM
In the past have you integrated this same "hard-coding" of functionality with the standard ASP.NET <asp:TextBox> control, or any other Control? If yes, I'm just wondering how that was accomplished.

jchau
Oct 08, 2008, 11:21 AM
We ended up creating a custom textbox that inherits from asp.net textbox. I was hoping ExtJS provides something that can do this in javascript. If not, I will just extend Ext.form.TextField and create the appropriate asp.net server control.

geoffrey.mcgill
Oct 08, 2008, 12:32 PM
So why not just inherit from <ext:TextField> and override/add your properties? I guess anyway you look at it, preventing developers from using the <ext:TextField> instead of your custom inherited TextField control is really best controlled by policy. Or, the good old "search and replace", and a gentle "reminder" to the developer whom did not follow policy.

Another option may be a Skins file, which could be setup to override all <ext:TextField>'s globally.

jchau
Oct 08, 2008, 12:39 PM
Thanks geoffrey. I will be extending the javascript Ext.TextField class and also create a new server class that inherits from Coolite's TextField. Reason I chose to extend the javascript class is just to reduce data sent to the client. I may have 10 textboxes on a form so I rather have the property set once in a cached javascript file rather than render the same javascript 10 times.

geoffrey.mcgill
Oct 08, 2008, 12:46 PM
Reason I chose to extend the javascript class is just to reduce data sent to the client. I may have 10 textboxes on a form so I rather have the property set once in a cached javascript file rather than render the same javascript 10 times.

That makes perfect sense and is a great approach.