[ADD] placeholder support on t-field

A placeholder is looked up:

1. in the field's options ("placeholder")
2. on the t-field node itself (@placeholder)
3. on the field's column (.placeholder)

The first one found is used as the @placeholder of the resulting node
(in-HTML), and displayed when the field is empty and unfocused.

If no placeholder is found, an empty field just gets a small padding
in order to be easier to see & focus.

bzr revid: xmo@openerp.com-20131218114901-xi3ye11x5pysq2a2
This commit is contained in:
Xavier Morel
2013-12-18 12:49:01 +01:00
parent 128f1e1281
commit 90a9e522f3
3 changed files with 29 additions and 5 deletions
+10 -1
View File
@@ -73,12 +73,21 @@ class Field(orm.AbstractModel):
def attributes(self, cr, uid, field_name, record, options,
source_element, g_att, t_att, qweb_context, context=None):
if options is None: options = {}
column = record._model._all_columns[field_name].column
attrs = [('data-oe-translate', 1 if column.translate else 0)]
placeholder = options.get('placeholder') \
or source_element.getAttribute('placeholder') \
or getattr(column, 'placeholder', None)
if placeholder:
attrs.append(('placeholder', placeholder))
return itertools.chain(
super(Field, self).attributes(cr, uid, field_name, record, options,
source_element, g_att, t_att,
qweb_context, context=context),
[('data-oe-translate', 1 if column.translate else 0)]
attrs
)
def value_from_string(self, value):
+7 -1
View File
@@ -211,9 +211,15 @@ ul.oe_menu_editor .disclose {
}
.cke_widget_editable:empty:after {
content: " ";
opacity: 0.3;
white-space: pre-wrap;
}
.cke_widget_editable:not([placeholder]):empty::after {
content: " ";
}
.cke_widget_editable[placeholder]:not(:focus):empty::after {
content: attr(placeholder);
}
.oe_carlos_danger {
outline: 1px solid red !important;
+12 -3
View File
@@ -171,11 +171,20 @@ ul.oe_menu_editor
// Breaks completely horribly crazy products listing page, so take it out.
.cke_widget_wrapper
position: static !important
// prevent inline widgets from entirely disappearing when their (textual)
// content is removed
.cke_widget_editable:empty:after
content: " "
white-space: pre-wrap
.cke_widget_editable
// basic config
&:empty:after
opacity: 0.3
white-space: pre-wrap
// no @placeholder -> just add some padding
&:not([placeholder]):empty::after
content: " "
// with placeholder and when not (yet) focused -> display placeholder
&[placeholder]:not(:focus):empty::after
content: attr(placeholder)
.oe_carlos_danger
outline: 1px solid red !important