Something like:

db.mytable.myfield.default = 'some\ntext\nwith\nline\nbreaks'
db.mytable.myfield.represent = lambda v, r: XML(v.replace('\n', '<br />'))
db.mytable.myfield.writable = False

With writable=False, no value will actually be submitted with the form -- 
the default value will simply be inserted with the new record. However, the 
represent function will be used to display the read-only value on the form. 
Note, you can also specify the above three attributes directly in the 
initial field definition:

db.define_table('mytable',
    Field('myfield', default=..., represent=..., writable=False))

Note, in the represent function, it is necessary to wrap the value in XML() 
so the <br /> doesn't get escaped when serialized in the response body.

Anthony

On Thursday, March 22, 2012 1:52:25 PM UTC-4, Brian F wrote:
>
> I am prefilling a field in an SQLForm, but there are other fields that the 
> user will fill out. The text I am prefilling I would like to display, but 
> not allow the user to edit it. I am setting the writable to false, but the 
> problem is the text I am filling with has multiple lines all separated by 
> newlines(\n). I need to keep the newlines because this data will eventually 
> be pulled out of the database, put into a file, and then loaded on some 
> hardware, so replacing the '\n' with <br> isn't really an option. The 
> problem is by setting writable to false, it converts the text just to 
> normal html text which doesn't understand newlines. I would like to either 
> put the data into a textarea, but I will need to disable it so the user 
> can't modify it, or figure out a way to replace the newlines with <br> but 
> only on the html page, and make sure newlines are entered in the database. 
>
> Any help is greatly appreciated.Thanks!
>

Reply via email to