MRCollective / ChameleonForms

Shape-shifting your forms experience in ASP.NET Core MVC
MIT License
254 stars 56 forks source link

Add possibility to replace EnumListHandler with custom implementation. #101

Closed zabulus closed 10 years ago

zabulus commented 10 years ago

I need to localize values of Enum in drop down list, but I couldn't find any possibilities to replace default implementation of EnumListHandler via Humanizer. Is there any override for this?

robdmoore commented 10 years ago

It is possible, but it involves creating your own version of Form that returns a different field generator than the DefaultFieldGenerator that uses a different implementation of the FieldGeneratorHandlersRouter (https://github.com/MRCollective/ChameleonForms/blob/master/ChameleonForms/FieldGenerators/FieldGeneratorHandlersRouter.cs).

You could then hook up your extended Form class via a different extension method on HtmlHelper (e.g. https://github.com/MRCollective/ChameleonForms/blob/master/ChameleonForms/Form.cs#L108).

Obviously, that's a lot of work and it's on the todo list in terms of making it easier to extend. I'd love to enable people to add in their own custom controls. Unfortunately, it's something that wouldn't happen any time soon as both @MattDavies and I are very busy.

I'm interested in how you would implement localisation with the enum though as maybe we can bake that support in. If you are willing to make a contribution to the project I'm happy to help you get it working.

zabulus commented 10 years ago

Looks like I've started panic earlier than it needed. I've read documentation of the Humanizer. And there is already localization mechanism for enums. I have little problem to put this in auto-generated datacontracts but this is another story. I think you should add this to documentation with link to Humanizer documentation. https://github.com/MehdiK/Humanizer#humanize-enums Thanks for fast reply.

robdmoore commented 10 years ago

Done: https://github.com/MRCollective/ChameleonForms/wiki/enum#explanation-and-example