Is there a simple way of stopping user from saving and publishing when a field is empty?
1 Answer
1) Publishing
To stop publishing when field is empty, there is no OOTB functionality. One option how you can achieve it with minimal effort is to put item (template) under workflow and use below approach to disable saving item when field is empty.
This will force content editors to fill in field values before saving and proceeding to next step of workflow. Afterwards they need to finish workflow and publish. Publish can be then manually or automatically when workflow is pushed to last step.
Without filling field, publishing won't be also possible.
2) Saving
You need to apply validation rules and especially FatalError to prevent saving of item when field is empty.
To achieve this you need to:
- Create similar validation rule as "Required" validation rule which is OOTB to achieve checking whether field is empty. By similar I meant exact copy (:-)) of '/sitecore/system/Settings/Validation Rules/Field Rules/Required' item
- Configure validation rule as FatalError - this will halt saving of item when validation fails - Set
Result=FatalError
as value ofParameters
field in your validation rule
- Assign validation rule for your item template - to be sure item is not saved in every scenario, you need to select the Validation Rules` section in item template and select the rules to apply in the fields “Quick Action Bar", “Validate Button”, “Validator Bar” and the “Workflow”.
More information
Validation rules:
- https://briancaos.wordpress.com/2011/05/09/using-sitecore-field-validators/
- http://sitecoreworld.blogspot.sk/2014/12/sitecore-validation-examples.html
- http://www.awareweb.com/awareblog/11-11-14-sitecore-custom-field
FatalError validation:
-
When I choose "Insert item", a dialog pops up asking me for the name of the new item. And then (AFAIK) the new item is immediately saved, with usually all fields empty; please correct me if I'm wrong. Assuming this is correct, would having validation rule(s) as you describe prevent the initial (automatic) save from actually happening? Or do the validation rules apply only after the initial (automatic) save?– Peter BCommented Feb 27, 2019 at 8:56