Try our conversational search powered by Generative AI!

Forms - replacing form elements with custom versions

Vote:
 

Hi,

In the solution I'm working with we have a need to add an extra property field to many of the form elements. After we extend each element and add the extra property we would like to replace the standard element block (from Forms) with the new block that we've created; so that site editors can only add our customized element to the form.

Is this possible to achieve?

Thanks!

#162214
Oct 12, 2016 15:27
Vote:
 

You can hide standard elements from editors in this way

[InitializableModule]
    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
    public class HideFormElements : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            Type[] formElementsToHide = new Type[1] { typeof(TextboxElementBlock) };

            var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>();

            foreach (var type in formElementsToHide)
            {
                var contentType = contentTypeRepository.Load(type);
                if (contentType.IsAvailable)
                {
                    var clone = (ContentType)contentType.CreateWritableClone();
                    clone.IsAvailable = false;
                    contentTypeRepository.Save(clone);
                }
            }
        }

        public void Uninitialize(InitializationEngine context)
        {
        }
    }
#162224
Oct 12, 2016 22:09
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.