In my MVC3 application, I have the following JavaScript that takes all textbox controls and all controls rendered with the .text-box .single-line classes and adds the class of ui-widget-content to make the site have a consistent appearance with my theme.
$('.text-box.single-line, textarea').not('.input-validation-error').addClass('ui-widget-content');
Though this works, it seems inefficient (adding classes after the DOM is loaded) and it causes page "flashing" (especially in FireFox).
I have read numberous articles on this topic, but can't seem to find a concise and clean solution. I know the following are options, but none seem to be as clean as MVC should be.
- I can change all EditorFor methods to the TextBoxFor with the
new { @class = "text-box single-line ui-widget-content" }htmlAttribute, but again, this is not very clean and would require hundreds of changes to controls that use EditorFor. - I can create an editor template that somehow adds the
ui-widget-contentclass for each data type, but that seems like overkill. - I thought about creating my own EditorFor, TextBoxFor, etc. methods in a custom HtmlHelper class that would override the existing methods which add the
ui-widget-contentclass. I thought this would be the cleanest solution, but I've read that it's not recommend to override extension methods. (Source: Overriding Extension Methods) - I would like to somehow tell the CSS file for the "text-box" class to simply add another CSS class to it, but I don't think that's possible (you can only add styles to a class not another class).
Are there any other options that will easily allow me to cleanly apply JQuery UI themes to existing MVC controls?