0
無效字段值I有一個定製的驗證類,檢查以下內容:防止保存在Sitecore的
文本字段的值應當具有長度爲5個字符。
前2個字符。應該是數字。
最後3個字符。應該是 字母。
當設置模板的標準值(例如:12a)時,指示器顯示紅色並顯示相應的消息。但在按Ctrl + S
後,即使出現錯誤,也會顯示要求保存的對話框。點擊確定後,會出現類似的對話框。點擊確定,將12a保存爲該字段的標準值。當我刷新內容編輯器時,值爲12a。
這是正常的Sitecore行爲。我期望如果價值無效,則不應該保存它的價值。
namespace CustomValidators
{
[Serializable]
public class testValidator : StandardValidator
{
private readonly Regex numbersRegex = new Regex(@"^\d+$");
private readonly Regex lettersRegexnew = new Regex(@"^[A-Za-z]+$");
protected override ValidatorResult Evaluate()
{
string value = base.GetControlValidationValue();
if (!string.IsNullOrEmpty(value) && value.Length == 5)
{
string firstPart = value.Substring(0, 2);
string secondPart = value.Substring(3, 3);
if (numbersRegex.IsMatch(firstPart) && lettersRegexnew.IsMatch(secondPart))
{
return ValidatorResult.Valid;
}
}
base.Text = "invalid value";
return base.GetFailedResult(ValidatorResult.FatalError);
}
protected override ValidatorResult GetMaxValidatorResult()
{
return base.GetFailedResult(ValidatorResult.FatalError);
}
public override string Name
{
get { return "testValidator"; }
}
}
}
我認爲你需要使用CriticalError而不是FatalError。你可以試試嗎? – Trayek
沒有運氣。我寫了這篇文章,其中說,'FatalError'是防止保存的那個。 http://www.awareweb.com/awareblog/11-11-14-sitecore-custom-field – Qwerty