Validation between different definitions in custom module
Hello
I am developing custom module for Sitefinity 4, and creating back-end edit controls with definitions.
I have 2 fields - Quote and QuoteName:
var quoteField = new HtmlFieldElement(container) ID = "quoteFieldControl", Title = "Quote", DataFieldName = (displayMode == FieldDisplayMode.Write) ? "Quote.PersistedValue" : "Quote", DisplayMode = displayMode, CssClass = "sfFormSeparator sfContentField", WrapperTag = HtmlTextWriterTag.Li, EditorContentFilters = Telerik.Web.UI.EditorFilters.DefaultFilters, EditorStripFormattingOptions = (EditorStripFormattingOptions?)(EditorStripFormattingOptions.MSWord | EditorStripFormattingOptions.Css | EditorStripFormattingOptions.Font | EditorStripFormattingOptions.Span | EditorStripFormattingOptions.ConvertWordLists) ;container.Add(quoteField);var quoteNameField = new TextFieldDefinitionElement(container) ID = "quoteNameFieldControl", DataFieldName = (displayMode == FieldDisplayMode.Write) ? "QuoteName.PersistedValue" : "QuoteName", DisplayMode = displayMode, Title = "Quote Name", CssClass = "sfTitleField", WrapperTag = HtmlTextWriterTag.Li, ;container.Add(quoteNameField);Hi Kronos,
The validation in a custom module is considered by design you can take a look at Productsdefinitions.cs in the products module.
var quoteNameField = new TextFieldDefinitionElement(container) ID = "quoteNameFieldControl", DataFieldName = (displayMode == FieldDisplayMode.Write) ? "QuoteName.PersistedValue" : "QuoteName", DisplayMode = displayMode, Title = "Quote Name", CssClass = "sfTitleField", WrapperTag = HtmlTextWriterTag.Li, ;quoteNameField.ValidatorConfig = new ValidatorDefinitionElement(quantityField) Required = true, MessageCssClass = "sfError", RequiredViolationMessage = Res.Get<ProductsResources>().TitleCannotBeEmpty, RegularExpression = "^[0-9]+[.]*[0-9]*$", RegularExpressionViolationMessage = Res.Get<ProductsResources>().TheQuantityMustBeAPositiveNumber ; mainSection.Fields.Add(quoteNameField);Thanks, yes, I know about SINGLE field validation with ValidatorConfig, it's pretty good by the way. But my goal is to create following scenario where TWO fields participated (Quote and QuoteName):
Quote is required if QuoteName value != null, and QuoteName is required if Quote value != null. If they are both null all ok.
e.g. Quote validation state depend on QuoteName property also. Does it make sence? I know it's hard task and ask you where should I dig, I don't need a code, just an idea how can it be implemented on current Sitefinity infrastructure
Hello Kronos,
This should be done with the single validation on each Element. The elements should have a condition (if). If the condition is true validation logic will apply if it is not true it will not validate the elements ( if both are null).
All the best,
Stanislav Velikov
the Telerik team