6

I need to add additional checkbox under Forms Settings tab.

How can I customize it?

enter image description here

1
  • @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, 2018 at 8:10

1 Answer 1

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" />
16
  • 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, 2018 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, 2018 at 12:28
  • 1
    I was just about to update answer with this information. Will do so in a second. Was creating screenshots... Oct 22, 2018 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, 2018 at 17:29
  • @siddharth Answer updated with more steps. Please check and give me feedback. Oct 23, 2018 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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