2

I have a field that is a required field validator in Sitecore. I marked that field as required and Set the parameter=FatalError so that users cannot save the item without entering data in that field.

The issue though is, I am not able to change the custom message when the user saves it. I get the standard message that says

"Some of the fields in this item contain fatal errors. You must resolve these errors before you can save this item".

I changed the title, description and text field but looks like it is not picking up from there. Any idea where should I change that message?

enter image description here

4

OOTB, you cannot change this message because this is present in the Sitecore Kernel dll. Please see screenshot below:

enter image description here

In order to change this message, you will need to override the validators pipeline

<processor mode="on" type="Sitecore.Pipelines.Save.Validators, Sitecore.Kernel"/>

So, it will be something as below:

public class CustomValidators
{
    public void Process(SaveArgs args)
    {
        Assert.ArgumentNotNull((object)args, "args");
        this.ProcessInternal((ClientPipelineArgs)args);
    }

    protected void ProcessInternal(ClientPipelineArgs args)
    {
        Assert.ArgumentNotNull((object)args, "args");
        if (args.IsPostBack)
        {
            if (args.Result == "no")
            {
                args.AbortPipeline();
            }
            args.IsPostBack = false;
        }
        else
        {
            string formValue = WebUtil.GetFormValue("scValidatorsKey");
            if (string.IsNullOrEmpty(formValue))
                return;
            ValidatorCollection validators = ValidatorManager.GetValidators(ValidatorsMode.ValidatorBar, formValue);
            ValidatorOptions options = new ValidatorOptions(true);
            ValidatorManager.Validate(validators, options);
            Pair<ValidatorResult, BaseValidator> strongestResult = ValidatorManager.GetStrongestResult(validators, true, true);
            ValidatorResult part1 = strongestResult.Part1;
            BaseValidator part2 = strongestResult.Part2;
            if (part2 != null && part2.IsEvaluating)
            {
                SheerResponse.Alert("The fields in this item have not been validated.\n\nWait until validation has been completed and then save your changes.");
                args.AbortPipeline();
            }
            else if (part1 == ValidatorResult.CriticalError)
            {
                string text = Translate.Text("Some of the fields in this item contain critical errors.\n\nAre you sure you want to save this item?");
                if (MainUtil.GetBool(args.CustomData["showvalidationdetails"], false) && part2 != null)
                    text += ValidatorManager.GetValidationErrorDetails(part2);
                SheerResponse.Confirm(text);
                args.WaitForPostBack();
            }
            else
            {
                if (part1 != ValidatorResult.FatalError)
                    return;

                // Changes to validation message goes here
            }
        }
    }
}

Note that I have copied the code from the Sitecore.Kernel.dll at the namespace Sitecore.Pipelines.Save.Validators. You can dotpeek that dll and see how sitecore implemented the fatal error message.

Finally, you need to patch the config file to add yours:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <processors>
      <saveUI>
        <processor patch:instead="processor[@type='Sitecore.Pipelines.Save.Validators, Sitecore.Kernel']"
            type="YourNamespace, YourAssemblyName" />
      </saveUI>      
    </processors>
  </sitecore>
</configuration>
  • Thank you . While this makes no sense from sitecore perspective that we cant override the message, atleast it helps me what i need to do now.. – Night Monger Dec 8 '17 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.