Reputation: 519
For a sitecore project, I need to validate the uniqueness of item names (to avoid url overlap)
It is possible to add the 'Duplicate name' Item validation rule to the item's template (to see these options, make sure 'show standard fields' is selected in the 'view' tab, in the content editor ribbon)
However, the options available here are to add the validation rule to the
Should I apply it as a workflow validation rule, and enable workflow (for all my content items)? That would work, but it seems like a lot of effort for the end user if they have to use workflow for something.
What I want to achieve is to simply show a validation message when the user tries to save the item (and uses a name which is already taken). Basically in the same way field validators work in sitecore
None of these choices seem to achieve this effect.
So my question is, what is the easiest way to achieve this?
Upvotes: 2
Views: 2900
Reputation: 494
I have a blog post out for this which uses the item create / save event. This was implemented and tested with Sitecore 7.2. Here's the config used:
<sitecore>
<events>
<event name="item:creating">
<handler type="MySite.Customizations.Customized_Sitecore.UniqueItemNameValidator, MySite" method="OnItemCreating" />
</event>
<event name="item:saving">
<handler type="MySite.Customizations.Customized_Sitecore.UniqueItemNameValidator, MySite" method="OnItemSaving" />
</event>
</events>
</sitecore>
Upvotes: 0
Reputation: 204
Validation Bar Validation Rules - Runs in the bar to the right of the content editor.
You may want to override the item:saving
event or the contenteditor:save
command. Take a look at item:saved
. The OnItemSaved
event triggers the Rules for an item.
If you change the dialog in the content editor or update the events, you'll want to make sure that your logic applies to specific parts of the content tree - i.e. sitecore/content/home, and/or possible security role.
I agree about the amount of effort regarding workflow, but in certain cases, may make perfect sense for this and other validation requirements.
Upvotes: 2
Reputation: 9
You can find a code example on SDN: http://sdn.sitecore.net/Snippets/Item%20Handling/Validating/Validate%20a%20particular%20field%20on%20the%20Item%20save%20event.aspx
Upvotes: 0