综合编程

Automatically bootstrap fields in Sitecore 9 Forms

微信扫一扫,分享到朋友圈

Automatically bootstrap fields in Sitecore 9 Forms
0

Sitecore Forms enables you to easily create forms by dragging and dropping fields. It also supports Bootstrap. However, if you want to use Bootstrap framework, you must follow a set of steps to add the proper wrapper and classes around each field. Needless to say, this approach is not user friendly at all.

In this post, I share with you a custom processor that automatically wraps fields and adds the proper classes to each input and label.

Bootstrap fields processor

First step is to implement the code for the custom processor. Add a new class and extend the Sitecore.Mvc.Pipelines.MvcPipelineProcessor passing the type RenderFieldEventArgs .

Figure 1: BoostrapFieldsProcessor class

The remaining of the code will use HtmlAgilityPack to manipulate the html of the fields at the moment they are rendered. You can find the code in my Github repository https://github.com/JANeto87/blog/tree/master/sitecore/forms/bootstrap .

Next step is to add the configuration file.

Figure 2: Configuration file

In the configuration, I add a list of fields to be manipulated. You don’t want fields such as Section, Submit and etc, to be changed.

The end result can be seen below.


Below you see the Bootstrap css classes added as well as the form-group wrappers.

Figure 3: The html of the fields are changed by the BoostrapFields processor

Credits

Photo by Nathan Dumlao on  Unsplash

阅读原文...


Avatar

Intel 300系芯片组不再是“中国制造” 转向越南生产

上一篇

Android Jetpack系列——DataBinding 最佳实践

下一篇

您也可能喜欢

评论已经被关闭。

插入图片
Automatically bootstrap fields in Sitecore 9 Forms

长按储存图像,分享给朋友