Can we write CSS for a label based on the attributes of its "for" attribute's value? - label-for

I want to write css for the labels of checkboxes based on checkbox enabled/disabled. I know the following methods, but I'm not satisfied with these.
Method1:
label[for="something"] {
/* woohoo! */
}
I want to write a generalized css. I do not want to repeat for every checkbox like above.
Method2:
input[type="checkbox"]:enabled+label{ font-weight: bold; }
this one directly picks the sibling and is not based on "for". I want to pick the label specifically that is associated with the checkbox and leave it alone if the label is not 'for' that checkbox.
How can I apply css based on a label's "for" attribute?

think your after the :checked pseudo-class rather than :enabled
input[type=checkbox]:checked + label {}
The above would select a label who was the next sibling after a checked input of type checkbox

Related

Calling a mixin with a return value twice in the same scope

I'm building a LESS file containing a list of color variables that are used through our project. Most of these colors are simple colors (red, blue...), but I want a few of them to be automatically "computed" from the other colors. For example, I have made a mixin to automatically create a color that "stands out" from another color. Following the LESS documentation, I "simulate" a return value by defining a new variable in the mixin, so that I can use it next.
.stand-out-color(#baseColor, #rate) when (lightness(#baseColor) >= 50%) {
#standOutColor: darken(#baseColor, #rate);
}
.stand-out-color(#baseColor, #rate) when (lightness(#baseColor) < 50%) {
#standOutColor: lighten(#baseColor, #rate);
}
.stand-out-color(red, 10%);
#my-first-color: #standOutColor; // A slightly different red, perfect
.stand-out-color(blue, 10%);
#my-second-color: #standOutColor; // The same slightly different red, not the blue I expected
Unfortunately, the return value is written after the first call, and never changed afterwards.
After reading the documentation again, I got this part: "There is only one exception, variable is not copied if the caller contains a variable with the same name (that includes variables defined by another mixin call)."
So it works as it should, but I don't have any idea how to achieve what I want, which is a function I can call more than once within the same scope. As I'm defining a list of global variables, I don't think I can play with scopes to avoid this behavior. Is there any other way to achieve this?
Here's the solution, thanks to seven-phases-max's comment to my question. It solves my initial problem, which is that I needed to compute slightly darker/lighter color variables depending on another variable.
The contrast function of LESS solves my issue, by letting me specify which color to take depending if a color is "dark" or "light".
Applied to my example:
#my-first-color: contrast(#original-color, darken(#original-color, 10%), lighten(#original-color, 10%));

How to specify different editor widgets for the same column in Dojo DataGrid

I am wondering, is there an official way to specify a different widget editor for the same column in a DataGrid (different rows)?
I found dojox.grid.cells._MultipleEditor, but it is quite complicated and not officially supported.
This is for creating things like a property sheet with DataGrid.
EDIT: People seem to suggest using dgrid. However, I am not sure if dgrid has this feature. Also, unfortunately, ... drum roll... horror music... I must support IE6.
Well, there seems to be a way to do it. Doesn't seem to show much negative side effects (so far)...
Create one column for each value type, one after the other.
Tag each column with a CSS class to indicate its value type (via classes). For example: classes="multivalue int"
For each column, tag it with the correct editor widget and the appropriate constraint & options.
Put styles on each row (with onStyleRow) that correspond to each type. For example, add a type-int class to the row that has an int type.
Put in a CSS style that initially hides all the multi-valued cells:
.dojoxGridCell.multivalue { display:none; }
Un-hide all the cells with the correct type:
.dojoxGridRow.type-int .dojoxGridCell.multivalue.int
{
display:table-cell;
*display:block; /* For IE6/7 */
}
For this to work, obviously, each row must match exactly one column.
Obviously, you must set all these fields to the same property name. DataGrid allows you to do that.
Put display:none (via CSS etc.) on all the header cells of multi-valued columns except the first one. Otherwise, you'll end up with too many header cells.

Displaying dynamic kanban colors according to record state in OpenERP 7

could someone tell me in what way I can display the items in a view kanban with a specific color according to the state that is the record.
I'm trying something like this
<div t-attf-class="#{record.state=='scheduled' ? oe_kanban_color_#{kanban_getcolor(1)} : oe_kanban_color_#{kanban_getcolor(0)}">
but I looked ALL elements and not only those who are in the "scheduled".
Thanks :)
If you have copy/pasted exactly what you typed in the view definition, then your t-attf- class attribute is malformed, and all record will have the following class:
class="#{record.state=='scheduled' ? oe_kanban_color_1 : oe_kanban_color_0"
which, due to CSS class precedence, will cause them all to have the oe_kanban_color_1 style.
A few hints:
To avoid coloring some records, you can omit the oe_kanban_color_X entirely in some cases
You can use a t-att-class attribute to allow arbitrary Javascript expressions, depending on what you want to do. In contrast, t-attf-class only allows replacing placeholders.
When comparing field values with Javascript operators you normally want to use the value or raw_value of the field, rather that the Field object itself. value will only differ from raw_value when the value needs specific rendering, such as dates, numbers, etc.
The kanban_getcolor() function accepts any integer or string and returns one of the 10 default kanban color indexes.
Based on the above, the following might be closer to what you tried to do (note the t-att-class attribute:
<div t-att-class="record.state.value == 'scheduled' ?
'oe_kanban_color_1' :
'oe_kanban_color_0' ">
Alternatively, you could use t-attf-class and let kanban_getcolor() pick a color based on the state string:
<div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.state.value)}">
That last example is similar to what is done in many default kanban views in the official OpenERP distribution.

How do I use multiple different UIFonts in a UILabel?

I have an UILabel in my UIView. The text of my label is dynamic: it's a web service call which returns to me the text that I will put in my label. Here's an example of the content of the label:
"this is an example of my text/nthis is the second line".
I would like to put the first line in a specific font (Helvetica-Bold 12px for example) and the second line in another font (Helvetica 15px for example). How i can do this?
Thanks for your answers.
Honestly I'd recommend using two separate UILabel instances, take your text and get an array via [string componentsSeparatedByString:#"\n"], then place object at index 0 in the first one, and if you have a second object, put it in the second label.
You could go for a static UIWebView and simply wrap your text into HTML+CSS. This will be much easier than doing all the layout in code.
Maybe what you are looking for is NSAttributedString.
Here is a example: iphone/ipad: How exactly use NSAttributedString?

How to use a single NSValueTransformer subclass to toggle the titles of multiple menu items

I would like to make some bindings that toggle item titles in a popup menu based on a single numerical value in a text field. Let me explain:
This is my UI:
I want my menu items to automatically adjust to singular or plural based on the number in the text field. For example, when I type "1" in the box, I want the menu items to be labeled "minute", "hour" and "day". When I type "4", I want the menu items to be labeled "minutes", "hours" and "days".
What I did to date:
I bound the three menu item's labels to the same key path as the text field's value.
I created an NSValueTransformer subclass to interpret the value in the text field and return singular or plural to be used as item titles.
I applied this value transformer to the three bindings.
The issue:
My value transformer can either return singular or plural but it can't set the appropriate string based on the menu item it's applied to.
It looks to me like a value transformer is generic and can't return different values for different destinations. That would mean that to have the three titles change automatically, I would need to have three different value transformers that return the appropriate string for each menu item. That doesn't seem optimal at all.
Ideally I would be able to combine a string stored in the destination menu item (let's say in the item's tag property) with an "s" in the value transformer when the text field's value is larger than one, or something similar that would enable me to use a single value transformer for all the menu items.
Is there something I missed? What would be an ideal solution?
Okay, this is probably not an ideal solution, but something you could consider: if you set your value transformers from your code (and not in IB), you could instantiate 3 different transformers of the same class. You could give your value transformer an ivar NSString *unit (and add something like [[MyValueTransformer alloc] initWithUnit:]) to allow each to return their own string, but you still have to write the value transformer's code only once.
(Also, if you're ever going to consider making your application localizable, simply appending an "s" to create the plurals is not going to work. You could of course add ivars for both NSString *singular and NSString *plural to do that.)
Edit: Wait, I just realized you can register value transformers! If you register them as MyValueTransformerHours and MyValueTransformerMinutes (by manually allocating and initializing them in your code), you can use them from Interface Builder. See also https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ValueTransformers/Concepts/Registration.html#//apple_ref/doc/uid/20002166-BAJEAIEE.