6

I need to add additional checkbox under Forms Settings tab.

How can I customize it?

enter image description here

  • @Peter Procházka we can not override UpdateItem and InitializeModel method as these methods are not virtual, it seems to me there is limitation from Sitecore. – siddharth Nov 30 '18 at 8:10
5

1. First step is to create new item under PageSettings for FormSettings in core database.

You need to add it in core database under /sitecore/client/Applications/FormsBuilder/Components/Layouts/FormSettingsPropertyGrid/PageSettings/SettingsForm item:

enter image description here

It needs to be created based on FormCheckBox Parameters template.

Exact path to that template:

/sitecore/client/Business Component Library/version 2/Layouts/Renderings/Forms/Form/Templates/FormCheckBox Parameters

or you can find it based on its ID also:

{AD75C314-F983-4C56-81D5-DC10D5CCF4EF}

You need to also enable this new control in ControlDefinitions field in parent item that is based on FormSection template. This needs to be done in order to render control under that form section:

enter image description here

There is already checkbox that you can use as starting point. Make your checkbox based on this item:

/sitecore/client/Applications/FormsBuilder/Components/Layouts/FormSettingsPropertyGrid/PageSettings/SettingsForm/Advanced/PerformanceTracking

enter image description here

2. Second step is to add new field on Form template itself.

You can do this but altering item template under this path /sitecore/templates/System/Forms/Form and adding your custom shared checkbox field:

enter image description here

You will refer to this field name in next step shortly.

I would recommend creating your own Form template based on OOTB one located under the path - /sitecore/templates/System/Forms/Form and reference your newly created one but the reference is on so many places that it would be hard to do so.

3. Third step is to add your newly created setting in FormsViewModel.

For that you would need to create your own model class in your solution that will inherit Sitecore.ExperienceForms.Mvc.Models.FormViewModel class. It is located in Sitecore.ExperienceForms.Mvc.dll.

You need to add new property of type bool or string depending your requirements:

enter image description here

Reference your field created in step 2 here as Fields["Your_Custom_field_name"].

You also need to set your fields value in UpdateItem method:

enter image description here

and InitializeModel method to get current value of your custom parameter:

enter image description here

4. Forth step is to alter Model class that will be used by Sitecore Forms.

Instead of OOTB Sitecore.ExperienceForms.Mvc.Models.FormViewModel,Sitecore.ExperienceForms.Mvc class you need to change Model Type field in Form item in master database in path /sitecore/system/Settings/Forms/Field Types/Form to your custom class created in step 3.

enter image description here

5. Last step is to create your own FormRenderingContext and make Sitecore Forms use it instead of OOTB one.

You need to inherit from Sitecore.ExperienceForms.Mvc.FormRenderingContext class and add properties around your custom property.

Create patch config file to change this serviceType to your custom class at the end.

From:

<register serviceType="Sitecore.ExperienceForms.Mvc.IFormRenderingContext,
Sitecore.ExperienceForms.Mvc" 
implementationType="Sitecore.ExperienceForms.Mvc.FormRenderingContext, 
Sitecore.ExperienceForms.Mvc" lifetime="Transient" />

To:

<register serviceType="Sitecore.ExperienceForms.Mvc.IFormRenderingContext, 
Sitecore.ExperienceForms.Mvc" implementationType="YouCustomImplementationClass, 
YourAssembly" lifetime="Transient" />
| improve this answer | |
  • i duplicated the IsAjax item and renamed it , also updated few fields to change the text. However i could not see that new item. I cleared the cache too. Any idea , what i am missing ? – siddharth Oct 22 '18 at 12:23
  • I need to select this newly added item at item - /sitecore/client/Applications/FormsBuilder/Components/Layouts/FormSettingsPropertyGrid/PageSettings/SettingsForm/Advanced – siddharth Oct 22 '18 at 12:28
  • 1
    I was just about to update answer with this information. Will do so in a second. Was creating screenshots... – Peter Procházka Oct 22 '18 at 12:29
  • The checkbox is coming but after saving the form again its get deselected. The checkbox is always unchecked after saving form. Any idea ? – siddharth Oct 22 '18 at 17:29
  • @siddharth Answer updated with more steps. Please check and give me feedback. – Peter Procházka Oct 23 '18 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.