how do I assign class for all textboxes created using textboxfor?
Is there a way using a template override?
I know there are template overrides by type, but I don't want to target a particular type. I want to add a rounded-corner css class to all textboxes.
I don't see a reason why MVC need to be in charge of rounding the text boxes. It would be much easier just to use CSS with a .input[type=textbox].
CSS:
input[type="textbox"]{border-radius: 0.5em;}
Adding a css rule(s) would be the best option for this, but if you need to add a class, this may be easier to achieve with a startup script and jQuery than on the server side:
$(document).ready(function(){
$(":input[type=text]").addClass("foo");
});
Related
I have developed new Plugin 'Small Caps' in CKEditor5. Basically, it should add span class or style as {'font-variant': 'small-caps'}.
I am trying with different editor methods, however, I am not able to find anything which can fulfill my requirement.
Does anyone know how can I achieve this? Do I need to make custom command class? Which API would add span attribute with css class or styleset?
We've created a plugin for this purpose:
https://github.com/HCESrl/ckeditor5-small-caps
I hope it helps!
I am using EditorTemplates to style all my input fields. Works like a charm, however now I want two themes of EditorTemplates, one for normal forms, and then one for my wizard forms.
I am already using an overloaded Html.BeginWizardForm() around those Html.EditorFor - but how do I make the MVC logic react on being inside Html.BeginWizardForm() ?
EditorTemplates are designed to be somewhat global. You can override them, though, just like any other view, because they are just views. For example, assuming you have something like Views\Shared\EditorTemplates\String.cshtml, you can then create a another view at Views\Foo\EditorTemplates\String.cshtml, and for any action called from FooController, the latter editor template will be used instead of the one from Shared. You might be able to make this work in your scenario if the wizard form is used in a specific controller or area context.
Short of that, though, there's no way to have this occur automatically. Some manual options still exist, though.
You can decorate the properties of the view model used within the context of the wizard with UIHint attributes. For example, assuming the same shared editor template above, you could do something like:
[UIHint("WizardString")]
public string Foo { get; set; }
That would cause it to look for Views\Shared\EditorTemplates\WizardString.cshtml instead.
You can pass the editor template to use in the call to EditorFor:
#Html.EditorFor(m => m.Foo, "WizardString")
All that said, the biggest problem here is that you seem to be violating a pretty core principal of good web design. HTML is about structure, not presentation. CSS is for presentation. As a result, if you want something to look different in a certain context, the correct approach is to apply different CSS. If things are designed well, your HTML shouldn't really have to change.
It seems is as stated by Chris Pratt not possible to have multiple EditorTemplates.
I however found a workaround by extending the MvcForm and created a WizardForm which adds a value to the ViewContext (in my case "wizardContext" => true) and on disposing setting wizardContext => false.
This allows me in the EditorTemplates to add a check for if I am inside or outside the wizardContext, which will propagate through the nested EditorFor, and in this way allow me to have different themes, without having to be specific in EditorFor.
So rather than spend time trying to make spans that are empty behave in IE 7, is there a quick way to make validation render inside of a div instead of a span?
If you are talking about the Html.ValidationMessageFor or Html.ValidationSummary helpers there is no easy way to modify the markup they are generating other than writing your own custom helpers. I showed some example here.
I'm using modelforms to generate forms.
wiek = models.PositiveIntegerField(verbose_name="Wiek")
Is there a way to assign CSS style to it? I don't want to create html for forms because it is too much work (complex forms). I want to generate them from models, but I want to style it too. How to create seperate CSS for each form?
Thanks for answer in advance
Well,
option 1:
probably you have code like this:
<form action=.......
{{form.as_something}}
</form>
If so, you can assign some special class to each <form> tag and than style it as you want.
option2:
if you need to style each field independently you can use fact that Django by default uses id_name_of_field conevention to name fields ids. So you can use #id_name_of_field in your css to style particular field.
option3:
in model form you can assign some attributes to each field's widget like:
self.fields['wiek'].widget.attrs['class'] = 'some-class'
How can i change the look of the jqgrid without changeing the stylesheet. Basically im using jqueryui to style my site but i want to use different background images for just the grid. Is this possible?
Is it that you want to apply several jQueryUI themes to the same page, and have jqgrid use one of them while having other elements in your page use the other?
You may want to look at this page which discusses how to add scope (I'm assuming the easy way is to have the rest of your page use the manually scoped theme, and have jqgrid use the "default" scope, unless you want to dig into the jqgrid jquery extension code to see how to use a custom scope)
I haven't done this, but the strategy that I would use would be to define some alternate styles for your grid, keeping the same basic CSS definition layout that jQuery UI uses, but redefining the style content the way you want it. I'd make sure that these styles are included after the jQuery UI style sheet. Then I would use javascript on document load to go and apply the new CSS classes to elements of the jqGrid that have the matching jQuery UI classes to your styles.
I think it will be a major pain as there are many classes and I'm not sure that I would do it since sort of defeats the purpose of having a theme.
.jqgrid-widget { ... override widget styles ... }
.jqgrid-widget input, .jqgrid-widget select ...
.jqgrid-widget-content { ... override widget-content styles ... }
$(function() {
$('#myGrid .ui-widget').addClass('jqgrid-widget');
$('#myGrid .ui-widget-content').addClass('jqgrid-widget-content');
...
});
This function removes all (at least almost all) the jquery ui candy
/* Remove jquery-ui styles from jqgrid */
function removeJqgridUiStyles(){
$(".ui-jqgrid").removeClass("ui-widget ui-widget-content");
$(".ui-jqgrid-view").children().removeClass("ui-widget-header ui-state-default");
$(".ui-jqgrid-labels, .ui-search-toolbar").children().removeClass("ui-state-default ui-th-column ui-th-ltr");
$(".ui-jqgrid-pager").removeClass("ui-state-default");
}