Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
11 Trả lời
15884 Lượt xem

I have a notes field with a type of text.

On the screen I enter: Note1 Note2 Note3

On the report it comes out as Note1 Note2 Note3

How can I get the line return to be honored in the printed output

Ảnh đại diện
Huỷ bỏ
Tác giả

Interesting that my formatting of Note1 Note2 and Note3 has been lost. There should be CR between each so they appear on 3 subsequent lines

Please upvote if the right answer was provided

Câu trả lời hay nhất

I found this in search, and while a few of the above did not work, this worked well. Split the string into an array, and iterate over them:

<t t-if="isinstance(o.field, str)">
   <t t-set="string_to_output" t-value="o.field.split('\n')" />
   <t t-foreach="string_to_output" t-as="string_line">
      <span t-esc="string_line"/>
      <br />
   </t>
</t>

Note, the first line tests if it's a string first. If not (null, false, etc), it may yield a server error when it tries to ".split".

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello Kevin,

The formatting from the text field does not transfer to html (what you should use inside the mako)

A good workaround for this solution is to use the <pre> tag and place o.notes inside it

Do not forget to reset the style on the pre tag or simply just change the font to the one you use

Another would be to add in the mako ${o.field.replace('\n','<br />').replace('\r\n', '<br />')} this will substitute the newline/return carriage + newline into breaks

Hope this helps you!

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

${note | carriage_returns} is what you looking for

with:

    <%
    def carriage_returns(text):
        return text.replace('\n', '<br />')
    %>

at the start of the document

Ảnh đại diện
Huỷ bỏ

That does not work for me on a regular text-field, am I missing something?

sorry i should post the complete solution

Ah I thought it was a default function, nice Markus

It is a default function on rml-reports so i was confused the first time, but now we are fine

Câu trả lời hay nhất

Why don't you use fields.html ? It's much better to customize your text to be printed.

'note': fields.html('Note')
Ảnh đại diện
Huỷ bỏ

Not changing existing fields, only print right in webkit reports

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 4 24
1899
12
thg 4 16
18056
1
thg 3 15
6096
1
thg 3 15
3815
2
thg 3 15
5786