Help

5

How to truncate text field ?

Hi folks,

Is there a way to truncate text of a fields.text() (in tree view especially), so that lines aren't huge in height ? I was thinking of a widget attribute in xml maybe ?

Thanks for your time. Nicolas

Avatar
Discard
2 Answers
3
Avatar
Quentin THEURET
Best Answer

You can use a fields.function with type='char'. The function to compute this field will give the fields.text value and truncate it.

Then, in the tree view, if you want the whole text, you display the fields.text otherwise, display the fields.function.

6 Comments
Avatar
Discard

Hi, thanks for the trick. it's a good work around if you are not willing to have inline editing (e.i. editable="bottom"). Because we can't have an editable function field.

Avatar
Camptocamp SA
-

This is not true, you can define the parameter fnct_inv to create the write method of function field. However, in your case I agree that it wouldn't be conveniant as you would need a truncated field only in view mode and a full text in edit mode. A widget might be the best choice.

I stumbled upon fnct_inv this morning to find that out .. how do you mean "a widget" .. writing a widget ?

Avatar
Camptocamp SA
-

Yes it is what I meant. Creating a widget that extends the base text widget and hides parts of the text only in view mode.

I'm ok to get into writing widgets but have no time for now. Would it be complex ? Any link examples / repo ?

I'm marking this answer as a solution because in the end it's the only quick way to achieve this. Except that the list view won't be editable inline. I'll show the function field inline, and the original text field in the form. Thank @all

3
Best Answer

Hi, there is a function which do that in 6.0, function truncate_data, you can find it here :

http://bazaar.launchpad.net/~openerp/openobject-addons/6.0/view/head:/mail_gateway/mail_gateway.py

update with new informations given by comment after :

if you can have status of the page, editable or browse, you can use function I gave before :

create a new field text which is updated by onchange with first you are already created.

in tree view in function of state of the page (editable or browse), one is visible, the second no.

Bye

6 Comments
Avatar
Discard

Hi, thanks for pointing this out to me but the idea here is to have a text field that can be fully edited inline, and that only shows so many characters when in browse mode. If the behavior doesn't exist, I'll post a feedback on http://feedback.openerp.com. These features are lacking, along with placeholders, rich text, etc.

Avatar
Cyril Gaspard (GEM)
-

I update my answer

ok, sounds like the answer I was looking for. Still have to detect the field/view state, any hint ? is it a variable available in xml (a bit like active_id, parent, etc) ?

I can't find in the view the boolean context variable set_editable mentioned here : http://doc.openerp.com/trunk/developers/web/list_view/#editability-status

Avatar
Cyril Gaspard (GEM)
-

I believe you do not understood what I would say by editable/browse. Editable is when you push a button create or edit, browse is a view in state read (I wanted just use terms you used yourself). By regarding your other new questions, attribute set_editable is to have a tree with lines editable without wizard form opened to modify value of fields, this is not the same thing. I do not if it is possible to have the status edit/read mode of a view. bye

Hi GEM, thanks for coming back to me. I understand both contexts are different. The link above discusses a javascript context accessed from the client side which could as well be a completely different context from the server side context. I created a new question to dig and clarify this topic.