0
votes

I have a Sharepoint list, where one of the columns is plain text - Description. When you edit a list item, Description field is normally a TextArea. I have it programmed that this TextArea is extended with JavaScript to accept rich text (html really), so I have my custom rich text field. The problem is that when I input the rich data everything looks fine but when I save the edited item and then display it, the text is displayed as plain text, not html, so instead of a bold text I get "< b >text< /b >". And I would like it to be displayed as html. What can I do with it?

Edit: I don't want to use the built-in editor, because I need some different behavious.

3

3 Answers

2
votes

The code that reads in the text input from the form and saves it to the list will be doing a HTMLEncode operation that replaces

< with &lt;
> with &gt;

and so on (look at the source of the page after a save)

This occurs 'server side' so you won't be able to change this using JavaScript.

You've got two options I think

  • As F5 mentioned you can create a custom field type with your own behaviour for rendering and update. This is the 'correct' way to do this.

  • You could change your funky javascript to work on a rich text field, hack into the rendering of the built in RTE and replace it with your own.

Of cource as soon as you are taking input from a user and then rendering it back to your web page you open yourself up to all sorts of nasties such as Cross Site Scripting if you are not filtering out potential bad stuff (the very reason why the HtmlEncode is used) - less of a problem in a typical SharePoint site on an Intranet than a public facing site.

0
votes

SharePoint supports rich text columns using its own in-built editor. You just have to change the column settings so it allows rich text.

If you are using a JavaScript editor because of browser compatability with the built-in rich text editor then SharePoint will always strip the html from whatever is entered as it expects the input to be plain text.

Re your comments

If you want the field to display in rich text it needs to be a rich text field, by setting it to plain text you are always going to lose your custom formatting.

You need to look into custom field types

0
votes

So where exactly are the data being displayed incorrectly: on the List Display Form or on a Page Layout? If it's on the Page Layout the fix is easy: create a custom Field Control which will retrieve the value of the field (like SPContext.Current.ListItem["YourField"]) and decode the contents to get HTML instead of encoded HTML entities.