November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Maybe this could give some inspiration: http://www.tech-fellow.lv/2013/05/localized-episerver-model-validation-attributes/
I know that there have been complaints that built-in localization should be working -> but I couldn't manage to get that on my local Alloy instance.
Are you trying to utilizing XForms to building out and save the form data? If not, you're probably just better off staying on the track you are doing... just using standard MVC to make the form, do validation, and your own logic to send/save the data. If you need to inject anything from EPiServer, you can do that using the API in the controller or the view. Then you can use EPiServer's LocalizationService (as Valdis uses in his blog post) to pull in translation data from an XML file, instead of using .RESX files.
I used the following code for required field validation. Just need to use resources xml and add a new attribute which inherits from RequiredAttribute :
public class LocalizedRequiredAttribute : RequiredAttribute
{
private readonly string errorMessageKey;
public LocalizedRequiredAttribute(string errorMessageKey)
{
this.errorMessageKey = errorMessageKey;
ErrorMessage = errorMessageKey;
}
public override string FormatErrorMessage(string name)
{
return ServiceLocator.Current.GetInstance<LocalizationService>().GetString(this.errorMessageKey);
}
}
Then in form model:
[LocalizedRequired("/common/firstnameerrormessage")]
public virtual string FirstName { get; set; }
[LocalizedRequired("/common/lastnameerrormessage")]
public virtual string LastName { get; set; }
[LocalizedRequired("/common/emailerrormessage")]
[Email("/common/emailvalid")]
public virtual string Email { get; set; }
Hopes some helpful for you
Im not really fond of the xml way either since it means that the site can't be translated and changed without hacking xml and redistributing files. Ideally everything related to displayed text and images should be changeable by the editors without having to bother the developers. It also helps if you can read the language when you add translations to se if it looks reasonable.
Not a fan of umbraco when it comes to handle multiple languages but they do have a dictionary editor built in. It would be nice to be able to do something like that.
For this project I'll stick to resource files, but for my next project when there is more time I'll look into making a translation page that i can pull translations from.
Take a look at this blog post. Sounds like something similar you are looking for: https://jstemerdink.wordpress.com/2013/06/20/a-custom-localization-provider-for-episerver-7-2/
I have based a site on the Alloy MCV and even though i dont really like the structure of the code I've managed to live with it and work with it until now.
Is there any examples how you should do a form with validation on a page? The form and validation messages needs to be translated into several languages as well.
This is what I have come up with on my own but it seems like there should be a better way.
The page consists of two parts, one list of items and a order form. The list is part of the view model and I fill it with the index action and that part seems fine.
The order form is made using a separate model that is part of the view model. The order model has data annotations so that i can make it validate with the standard MVC way including javascript validation.
To translate the validation messages and fields I fell back on resources(resx) files and it seems to work but It feels quite stupid to introduce a third way of translating stuff (on page, xml files and now resource files).
So is there any working examples how to do something like this? Just a "simple" form with validation and translation.