Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Client validation not working when using custom attribute in specialized property

Vote:
 

Hi,

I have a specialized property in episerver named LocationInformation with a below given structure:

    public virtual string Name{ get; set; }

    public virtual string City { get; set; }
 
    [RegularExpression("^(\\+\\s?)?((?<!\\+.*)\\(\\+?\\d+([\\s\\-\\.]?\\d+)?\\)|\\d+)([\\s\\-\\.]?(\\(\\d+([\\s\\-\\.]?\\d+)?\\)|\\d+))*(\\s?(x|ext\\.?)\\s?\\d+)?$", ErrorMessage = "Invalid Phone Number")]
    public virtual string PhoneNumber { get; set; }

The phone property is not a required one & the given regex handles it fine. With the regex, validation kicks in the next instant.

Issue
Now when i create a custom attribute with the same regex in it ,the validation only kicks in when the page which includes this specialized location property is published.

Could some one shed some insights on why client validation kicks in with regex & not with custom attribute?

Additional details:

This specialized LocationInformation property is part of a block.Here is the code for the same:

public class ContactBlock : SiteBlockData
    {           
        [Display(Name = "Locations", Description = "Locations", GroupName = SystemTabNames.Content, Order = 40)]
        [DistinctLocationInformation]
        [EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<LocationInformation>))]
        public virtual IList<LocationInformation> LocationInformations { get; set; }
    }

This Contact block once configured is added on a standard page by the editor.

Note: [DistinctLocationInformation] is a custom attribute to check for any duplicate locations if any when you publish the contact block.

Regards.

#265012
Edited, Oct 13, 2021 19:18
Vote:
 

Please write a bit more, are those properties part of block that is then used on a page? Or part of List<T> property?

Ideally please share the code for all models used.

#265053
Oct 14, 2021 7:18
Farhin - Oct 14, 2021 8:52
To answer your question,yes this specialized property(LocationInformation) is part of a block (Contact Block )that is used on a page.Edited the question with more input.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.