Monday 4 February 2008

Locking Down Styles in the MOSS Publishing HTML Field Control

In SharePoint Designer, open a page layout and select a HTML field controlYou should then be presented with a series of properties in the Tag window.There are a series of AllowBlahBlah properties which you simply set to false if you want that specific validation enabled on the field control.You can also set these properties in code view on the page layout
Descriptions of these field control properties from the MOSS SDK - http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.publishing.webcontrols.richhtmlfield_members.aspx

Name
Description
AllowExternalUrls
Gets or sets the constraint that allows external URLs in the HTML when validating the value in this RichHtmlField object.
AllowFonts
Gets or sets the constraint that allows font element tags to be added to the HTML.
AllowHeadings
Gets or sets the constraint that allows heading tags to be added to the HTML.
AllowHtmlSourceEditing
Determines whether you can switch the HtmlEditor object into a mode where the HTML can be edited directly.
AllowHyperlinks
Gets or sets the constraint that allows hyperlinks to be added to the HTML.
AllowImages
Gets or sets the constraint that allows image tags to be added to the HTML.
AllowLists
Gets or sets the constraint that allows list tags to be added to the HTML.
AllowReusableContent
Gets or sets the flag that enables the reusable content picker button when editing this field.
AllowTables
Gets or sets the constraint that allows table handling tags to be added to the HTML.
AllowTextMarkup
Gets or sets the constraint that allows explicit text markup tags, such as bold and italic, to be added to the HTML.
What happens when they are set to FALSE?Eg. If I set AllowFonts="False" and AllowTextMarkup="False"It disables the font and text colour buttons on the HTML Editor.
If a content author pastes in HTML with Font tags or text mark-up in the field control and now attempts to save or check in the page :You get this on the Page Editing Toolbar -
And the HTML Field Control now contains an Auto Correct button and a message related to ‘unsupported formatting’Now simply click the Auto Correct button, and the content is cleaned up client side with javascript, nice What happens to the HTML?BEFOREFONT color=#ff8000 size=5>WesTrac has a huge range of reliable low hour used equipment, all meticulously prepared for resale. If you can’t find exactly what…AFTERWesTrac has a huge range of reliable low hour used equipment, all meticulously prepared for resale. If you can’t find exactly whatOne more thing…If you set any of these properties to false it won’t automatically go through and clean-up the content in your site, but if a page contains content with these tags, the next time a content author edits the page and tries to save or check-in this validation will kick-in and it won’t let the user save the page unless they click the button to clean up the HTML.
Copy and Pasting Content from Word DocumentsYou can still paste in content from Word Documents, and this won’t automatically clean-up that HTML, these settings only seem to affect explicit font tags or other text markup, not in-line styles…
You get the following icon showing up in the field control You can also access remove inline styles from the floating tool-bar BEFORE

Sezai’s pasting this content in from word!

AFTER

Sezai’s pasting this content in from word!

ConclusionThere is no AllowStyles or AllowInlineStyles property! That’s dumb because I can paste in content from word that is setting Font and Font Colour with inline styles !That means even though I have set the following properties to false AllowFonts="False" and AllowTextMarkup="False" I can still set different fonts and font colours in Word, then paste it into a page, and save and check-in the page !!! and MOSS will let me… you need to remember to always click the Remove Inline Styles explicitly.

No comments: