This blog post describes validation features that can appear in the Page Editor user interface of revisions 120427 and later of version 6.5 and later of the Sitecore ASP.NET web Content Management System (CMS). The Field Validation in Page Editor? thread on the Sitecore Developer Network (SDN) and the release of 120427 with relevant features prompted me to write this blog post. For more information about data validation in Sitecore, see the blog post Validation in the Page Editor of the Sitecore ASP.NET CMS
Unlike earlier versions, Sitecore CMS 6.5 rev. 120427 and later of version 6.5 and later of Sitecore CMS support data validation in the Page Editor. To summarize the implementation quickly:
The Sitecore.Pipelines.GetPageEditorValidators.GetPageEditorValidatorArgs class exposes the following properties:
All of the default processors in the getPageEditorValidators pipeline exist in the Sitecore.Pipelines.GetPageEditorValidators namespace and largely populate the Validators collection of the Sitecore.Pipelines.GetPageEditorValidators.GetPageEditorValidatorArgs passed to the processors. The getPageEditorValidators pipeline contains the following processors by default in this order:
More information about Sitecore CMS 6.5 rev. 120427 (also called Update 4): sitecorekh.blogspot.com/.../sitecore-releases-650-update-4-rev.html
This feature is a real burner, the only drawback I see is that it only validates data from the context item :( Is there a way to add functionality to validate all changed fields, not only those from the context item? Regards, David
Hi David, I am relatively certain that there is no default way, but I think it should be possible. I see three possible approaches; without trying each, I am not sure if each would work or which might work best. This is the order in which I would attempt: 1. Override the Sitecore.Shell.Applications.WebEdit.Commands.Save command to (if the WebEdit.EnableValidation setting is true) iterate the fields returned by the Sitecore.Shell.Applications.WebEdit.Commands.WebEditCommand.GetFields() method, which I assume returns the fields updated, which identify the affected items. Replace the existing call to GetValidators() for the context item with something that loops over those items and populates the list. It appears that the Validation processor in the saveUI pipeline saves all of the updated items, and I think this would cause that pipeline to run validators for all of them. 2. Implement getPageEditorValidators pipeline processors to add validators for the other updated items. 3. Implement an item:saving event handler to run validators if the user is in the Page Editor and the WebEdit.EnableValidation setting is true to block the save operation in case of invalid data. One issue may be that the Validators processor in the saveUI pipeline generates messages that say "the item", which you might want to change to "an item". So it might be hard for the user to identify which data is invalid from the Page Editor user interface, as nothing appears in the chrome that surrounds fields. There may be other reasons that Sitecore chose to validate only the context item. Regards, -John
@David: I posted my attempt at overriding the command to validate the other items here: sdn.sitecore.net/.../ShowPost.aspx
Thank you John, I will give it a try! Best regards, David
Someone within Sitecore pointed out that Sitecore actually invokes field validation rules for all relevant fields in the Page Editor, but global and item-level validation rules only for the context item. I update the blog post accordingly. I am not sure that global and item-level validation is appropriate in the Page Editor, as it might not be possible for the user to correct those issues, especially in items other than the context item. Therefore, I would not override the Save command to apply additional validation.
It appears that validation in the page editor only invokes validators for which the GetMaxValidatorResult() method returns CriticalError or FatalError, and validators configured for the validator bar.
Hi John , Could you please elaborate how do we override Override the Sitecore.Shell.Applications.WebEdit.Commands.Save.
@Asif: I think you can override the save command. The location of the class and the config file that specify it appear to depend on the version. In 7 I see this in /App_Config/Commands.config: command name="webedit:save" type="Sitecore.Shell.Applications.WebEdit.Commands.Save,Sitecore.Client" / In 8 (and I think 7.5) I see this from /App_Config/Include/Sitecore.ExperienceEditor.config: command name="webedit:save" type="Sitecore.Shell.Applications.WebEdit.Commands.Save, Sitecore.ExperienceEditor" patch:source="Sitecore.ExperienceEditor.config" /
Hi John, Good Afternoon,Could we validate a component,not to use more than once in a web page under page editor mode ?if,you have already have a blog on this,could you share the respective url for this query Thanks Bansi.
@Bansidhar: I would try to validate the layout details field (basically, iterate the list of renderings and ensure that those you care about appear at most once). I do not think that this validation should be specific to the Page Editor. This should give some pointers, but you would want to confirm that this is still accurate for the current version (Sitecore may by now have addressed limitations in previous versions): www.sitecore.net/.../Validate-Layout-Details-in-the-Sitecore-ASPNET-CMS-Part-1.aspx www.sitecore.net/.../Validate-Layout-Details-in-the-Sitecore-ASPNET-CMS-Part-2.aspx Ensure that you validate the expanded layout details (with inheritance, deltas, and translated/versioned data applied).
how to customize sitecore fatal error message?