Django modelform and CSS styling - django-forms

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'

Related

How to conditionally add a class to a Magnolia component template based on the presence of another Component?

I would like to apply a class to my title component in Magnolia only if the content editors have chosen to add the subtitle component to a page. Example of what I am trying to do below:
[#assign subtitle = "somehow get a reference to the subtitle component"]
[#assign subtitleExists = subtitle?has_content]
<div class="title ${subtitleExists?then('removePadding','')}">
${model.render('titleCopy')!}
</div>
Is this possible? I am happy to add more information to help clarify what I am trying to do here if needed. Thanks!
Components are atomic, hence they normally don't see each other and can't influence each other. That would be job of the area grouping the components or parent component or the page itself.
That said, if the structure of the page and of your templates doesn't allow you any other solution, you might set some flag via request attribute in subtitle component and then check for the existence of said flag in your component.
Something along the lines of ctx.setAttribute("subtitleExists", true, 1) on one side and ctx.getAttribute("subtitleExists") on the other side. 1 stands for the local (request) scope for the attribute.

Create page division / format page?

I need to create a page division in Alloys XML, like a <div> tag in HTML
Basically it needs to be able to be variable size, have attributes like font, colour, border ETC and most importantly it needs to have sub tags such as label and button inside
I've tried using sperate views from this and requiring them into the current window. I've also tried using modules, but I'm not sure if I did it correctly.
My question is, what would be the best way to go around this?
You can create a Widget for this: https://wiki.appcelerator.org/display/guides2/Alloy+Widgets
It is basically a reusable component which you can pass parameters into and it has a own controller, style and view file.
In your XML file you can use it like this:
<Widget src="foo" name="button"/>

Web Forms For Marketers (WFFM) Rich Text Field Type

I need to create a custom field type in WFFM to accept rich text, and provide Sitecore's WYSIWYG editor for the user on the front-end. The form will be used to create a content item, and the rich text field will map to a field on that item's template. Has anyone done this? Can the Telerik editor be leveraged for this?
If you need a simple WYSISYG editor on the front-end, then you can use any of the numerous open source editors available on the web. I would be wary of using the Telerik editor included in Sitecore unless you have the relevant licenses.
If you use a Multi-Line Text field on the form, Sitecore outputs a regular <textarea> on the front-end. I suggest you add a custom css class under /sitecore/system/Modules/Web Forms for Marketers/Settings/Meta data/Css Classes and select that from the CSS Class drop on the left when you select your field in the form designer, in order to allow you to target specific fields to be WYSIYG'd.
Add a reference to the javascript file and then instantiate your editor, passing in the css class defined above to only target those specific textareas.
If you are using ASP.Net MVC and CKEditor (for example):
Add reference to javascript in /Views/Form/Index.cshtml. You may need to add this to your Visual Studio from the WFFM module package.
Or add the reference in <head>:
<script src="/path-to/ckeditor/ckeditor.js"></script>
Add the bottom of Index.cshtml (or just before your closing </body> tag), instantiate your editor, targeting only those <textarea> with specific css classes
e.g.
<!-- markup generated by WFFM -->
<textarea class="wffm-rte" data-val="true" data-val-length="..." data-val-required="..." id="wffm-generated" name="wffm-generated"></textarea>
<script>
// Replace all <textarea class="wffm-rte"> elements with CKEditor instances.
CKEDITOR.replaceAll('wffm-rte');
</script>
Be sure you sanitize your incoming data, you don't want a case of bobby tables.

How to use images in a selection form (for example checkboxes) in elgg

How could I use images in a selection form like this in elgg? Here's the example image of what I want to do:
Thank you so much!
You can create checkboxes with plain HTML or use the input/checkbox or input/checkboxes views to generate it for you. All of those let you use arbitrary HTML for the label, so you can use an IMG element.

mvc 3 assign class for all textboxes

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");
});

Resources