Django Crispy Forms: Replace Label and Radio Buttons with Images - forms

I have a form where a certain field is a radio selector with 3 options. Let's say this represents Good, More-or-Less, and Bad.
I managed to put them in the same line with InlineRadio, like this:
self.helper.layout = Layout(InlineRadio(field_name))
Now, I need to 2 things:
1) replace each option, that is rendered as a radio-button and its label with a pre-defined image.
2) Add 2 images, one to the left and one to the right of the radio buttons. So, at the end, I'll have 5 images in a row. From left to right: Image of Smile (just the image) - Image of selector (Good) - Image of selector (More-or-Less) - Image of selector (Bad) - Image of Sad face (just the image)
Is it possible to achieve them with django-crispy? If not, how can I achieve this?
Thanks in advance.

I'm the lead developer of crispy-forms. You could do this using Field layout object and using a custom template.
Field('field_name', template="custom_inline_radio.html")
Other option you have is to create your own layout object subclassing InlineRadio. That way you would only have to do:
CustomInlineRadio('field_name')
Actually, what you try to do is basically override the output of a default widget in Django and that probably makes more sense if you use a custom widget in your Django form, crispy-forms will play great with it. I wrote an article on widgets and Django forms that might interest you.

Related

Styling a Radio Button Group using the purecss.io framework

The other day I stumbled on the Pure project - a set of CSS modules released by the YUI team. I wanted to standardize the forms across my website and I liked the look of their forms module. Especially the style of form they call the Aligned Form. I added the CSS to my site and added the needed styles to my form and it all worked well except for my group of radio buttons. In the Aligned Form each input has a label on the left side and the input to the right of it's label. But individual Radio Buttons have individual labels - which get styled to the right of the button. What I'm looking for is a way to add an overall label for the group of buttons that is styled to the left and centered.
I did find a workaround, but I'm looking more for a dedicate "Pure" way of doing it.
My workaround was to include the radios within a fieldset, and use the legend of the fieldset as the label for the radio group.
I'd enjoy hearing from others who work with Pure Aligned Forms to see how you handled this.
Your question is a little vague I think. If what you are trying to achieve is something like this,
Label
radio
radio
radio
then the way you did it (what you call your "workaround") is actually the best way to do this. Fieldsets are meant for grouping items together and you can use the legend as the label.
However, if you are trying to do something like this,
radio
Label radio
radio
then you are going to want to use floating divs (one to hold your label and another to group your radio buttons).
I can't really get more specific without knowing what your code looks like and what you are specifically going for...

GWT Celltable column with label and image

I am looking to add a label and image to a CellTable column, with following requisites:
- Label should be followed by an image.
- Click on the column (anywhere on label or image), toggles the image.
I am thinking of creating a custom widget containing an HorizontalPanel. Which in itself contains the Label and Image. Before putting substantial time on the same, just want an confirmation whether this approach is proper ?
No, you cannot put a widget in a CellTable. You will have to make a custom cell (extend AbstractCell) and generate HTML directly.
Take a look at GWT's implementation of different cells to see how they achieve clicking, etc. There are no nice ClickEvents, for example - you have to respond to the browser events directly.
To toggle an image you will have to re-draw the entire table, or use crazy javascript that you don't want to use.

how to add a disclosure panel to a cellTable column in GWT

I have a cellTable with 5-6 columns. I want to put a plus icon in each row on clicking of which will display the details maybe in a disclosure panel. I have been looking around for a while now and I cannot find any information on how to achieve this. Could someone point me in the right direction?
i suspect i probably have to add a cellTree to the column? how do i go about this?
Thank you for your response in advance.
There is work in progress to allow expandable rows in CellTable among other features (maybe GWT 2.3). You can see more details here:
http://groups.google.com/group/google-web-toolkit-contributors/browse_thread/thread/b4a8a6e3c98ac061#
If that is not enough or you can not wait untill it is released I can think of two ways to achieve it:
As you said, using a CellTree.
Creating a custom cell that stores
state (open/close). Depending on the
state the cell will render
differently. In same way it is
similar to how EditTextCell works, in
"edit" state it renders an input
field while in "normal" state it renders
simple text.
I'm trying to do that too ... I managed to mimic that functionality toying with the html and a custom cell class that allows clickable pictures.
It is working for normal content such as text but if you'd like to get an asynchronous data to show in the expended line, I don't know how to do it ... (I'm trying to do exactly that).
Also, it doesn't look good because the columns don't align well ...
So what I've done is:
- create a custom cell class to display a picture (right pointing triangle, looking like the triangle in the disclosure panel)
In the click event get the HTML code of the selected row and copy it. Replace the content of the row (all cells) in the table with only one cell with its colspan set to number of columns. In the cell, add a table with first line the copied row and second line the content to display as expanded.
Get the image to sink an event for closing. In event, reset the original row that we copied.
I hope it helps.

Can I use the text correction ui element on a normal UIView

I'd like to use the text correction ui element in my own UIView.
Is this allowed & possible? If so, how can I use the element?
Clarification: I don't want to use it as a text correction feature.
I want to use it as UI elements to show multiple (dismissable) tags on a UIView to show & modify predicate settings.
You can use UIMenuController, which might be close to what you want (it's the thing that shows the Cut/Copy/Paste/Replace menu in text fields). See the CopyPasteTile and Touches sample code for details.
If you actually mean the thing that pops up with spelling completion suggestions, then no, you can't easily use it. You'll have to create custom buttons as you mentioned above. But, try downloading and running UIKit Artwork Extractor to help with getting UIKit artwork to match the look of your custom buttons.
Text correction? Do you meant the auto-complete / correct features you get when you type text on iOS? If so, you get that for free as part of UITextField or UITextView, so the answer would be yes. You can define exactly what you want corrected as part of the properties of those two classes.

Smartgwt - create a panel with title and a border

This sounds like a pretty simple thing to do but I havent been able to find an easy way to do this. How do I create a panel with a title and a border which can contain my widgets? I have seen the SectionStack class which provides this. But I dont want to create a section stack.
Window can be added to a layout and drawn. But is it the only way or is there a container class that I am missing?
Also, how does one center things? Say a textfield and a button at the center of the page. How is this achieved?
If you are using a DynamicForm, you can give it a border and title with
form.setIsGroup(true);
form.setGroupTitle(title);
This actually works for Canvas, too (which is the superclass of most widgets and layouts in SmartGWT).
(I just had the same problem, and found this question, as well as the thread Is there a "titled Border" on the SmartGWT Forums, which gave this answer. I tried and it seems to work.)
To do form-related tasks, look into DynamicForm. To set the inputs in the form, you use setItems(Item...). A text field is a TextItem. You set it's title to control the label that SmartGWT will build. To get a title for the form, the best I've come up with is to use a container canvas that will contain both the title (probably a Label element) and the DynamicForm. To center the inputs, I believe you'd need to use setAlignment on the DynamicForm.
You could create an object that is actually a VLayout that contains a Label (the tile), has a border as you need and includes a Canvas (the generic stuff you want included).
In my experience, I noticed that very often I have a DynamicForm visible, so I just add a BlurbItem control to diplay the tile and a small explanation.