Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sébastien Richer 194 posts 430 karma points
    Jul 02, 2013 @ 21:51
    Sébastien Richer
    0

    Wiring up my model's data annotations for error message to dictionary

    I have this simple contact form with 3-4 fields and some error messages driven by data annotations (like required and data format). I would like those values to be pulled from Umbraco, ideally from dictionary items. This is also mainly because these error messages need to be localized in different languages.

    My alternative will possibly be .resx files. But I was wondering if there is a fun / smart way to do this with Umbraco's data / cms driven functionnalities so that my content users can edit these.

    Thanks!

  • Jarno 21 posts 152 karma points
    Feb 06, 2019 @ 14:58
    Jarno
    0

    Hi Sébastien,

    Did you in the meantime found a way to get the errormessages from the umbraco dictionary? Hope you can help me.

    Thanks!

    Jarno

  • Harry Spyrou 212 posts 604 karma points
    Feb 06, 2019 @ 15:08
    Harry Spyrou
    0

    Well, now I know what I'll be doing during the weekend, whether you've found a solution or not. This sounds cool

  • Sébastien Richer 194 posts 430 karma points
    Feb 06, 2019 @ 15:20
    Sébastien Richer
    2

    Unfortunately, this was 6 years ago haha :D I really don't remember how I handled the case :)

    This was before Umbraco 7 if my memory serves well.

    If you guys find a fun way to do this, do share !

  • Jarno 21 posts 152 karma points
    Feb 06, 2019 @ 15:50
    Jarno
    101

    Thanks for your reply. I found a way with custom atributes so i'm implementing it on this way now.

    public class UmbracoRequired : RequiredAttribute, IClientValidatable
    {
        public UmbracoRequired(string umbracoDictionaryKey)
        {
            this.ErrorMessage = Helpers.Dictionary.TranslatedLabel(null, umbracoDictionaryKey);
            this.ErrorMessageResourceName = null;
        }
    
        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            yield return new ModelClientValidationRule()
            {
                ErrorMessage = this.ErrorMessage,
                ValidationType = "required"
            };
        }
    }
    

    Helpers.Dictionary.TranslatedLabel(null, umbracoDictionaryKey); is a function that gets the text from my umbraco dictionary.

Please Sign in or register to post replies

Write your reply to:

Draft