Data Annotations in Nested Data Models not validating
See original GitHub issueHi there I’m currently stucked with a problem I don’t understand why it’s happening. We’re using the Cofoundry Web Admin 0.6.1 NuGet Package which has been published on April 13th 2019.
The following is a code snippet from our nested DataModel of a product slider we’re building for a book webshop.
public class ProductPickerSlideDataModel : INestedDataModel
{
[PreviewTitle]
[Required(ErrorMessageResourceName = "Required_ISBN", ErrorMessageResourceType = typeof(Localization.Web.CMS.Global))]
[RegularExpression(@"^(?:97[89][- ]?)?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X]$", ErrorMessageResourceName = "MalformedISBN", ErrorMessageResourceType = typeof(Localization.Web.CMS.ProductPicker))]
[Display(Name = "Suche", Description = "Geben Sie eine ISBN oder eine ISSN ein, um nach einem Titel zu suchen.")]
public string Query { get; set; }
}
Currently the Required
annotation works partially here, as the field is marked as required correctly and the message “This field is required” does appear if I’d leave it blank. But in fact, it should show another message defined in our localization resource. The RegularExpression
annotation doesn’t work at all, so I could enter “Hitchhiker’s” instead of an ISBN and it gets recognized as valid while in fact it’s not. Does anyone know some help here? What am I doin’ wrong?
Kind regards and thanks in advance.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
@HeyJoel I’m not a backend developer so I might not be very helpful here but as mentioned it already works in Cofoundry’s
IPageBlockTypeDataModel
. Maybe this helps to figure out how to replicate the correct behavior 👍Lookin’ forward to the fix, good luck and thanks for your help!
Server-side validation now runs before adding/updating a nested data model. This will be released in 0.8.1.